Skip to content

Commit

Permalink
Removed change_ownership from all contracts.
Browse files Browse the repository at this point in the history
Rewrote tests to use two step ownership change only.
  • Loading branch information
kubaplas committed May 9, 2024
1 parent f84eb90 commit caef09a
Show file tree
Hide file tree
Showing 33 changed files with 28 additions and 194 deletions.
4 changes: 0 additions & 4 deletions dao/src/bid_escrow/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,6 @@ impl BidEscrowContract {
/// [`Read more`](AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);

/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);

/// Adds a new address to the whitelist.
/// [`Read more`](AccessControl::add_to_whitelist())
pub fn add_to_whitelist(&mut self, address: Address);
Expand Down
3 changes: 0 additions & 3 deletions dao/src/core_contracts/dao_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ impl DaoNft {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// [`Read more`](AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
/// [`Read more`](AccessControl::add_to_whitelist())
pub fn add_to_whitelist(&mut self, address: Address);
Expand Down
3 changes: 0 additions & 3 deletions dao/src/core_contracts/kyc_ntf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ impl KycNftContract {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// [`Read more`](crate::modules::access_control::AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
pub fn add_to_whitelist(&mut self, address: Address);
/// Remove address from the whitelist.
Expand Down
3 changes: 0 additions & 3 deletions dao/src/core_contracts/reputation/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ impl ReputationContract {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// See [AccessControl](AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
///
/// See [AccessControl](AccessControl::add_to_whitelist())
Expand Down
3 changes: 0 additions & 3 deletions dao/src/core_contracts/va_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ impl VaNftContract {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// [`Read more`](crate::modules::access_control::AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
/// [`Read more`](crate::modules::access_control::AccessControl::add_to_whitelist())
pub fn add_to_whitelist(&mut self, address: Address);
Expand Down
3 changes: 0 additions & 3 deletions dao/src/core_contracts/variable_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ impl VariableRepositoryContract {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// [`Read more`](AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
/// [`Read more`](AccessControl::add_to_whitelist())
pub fn add_to_whitelist(&mut self, address: Address);
Expand Down
14 changes: 0 additions & 14 deletions dao/src/modules/access_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ impl AccessControl {
self.whitelist.add_to_whitelist(caller);
}

/// Changes the ownership of the contract to the new address.
///
/// # Events
/// Emits [`OwnerChanged`](crate::modules::owner::events::OwnerChanged) event.
///
/// # Errors
/// Throws [`NotAnOwner`](crate::utils::Error::NotAnOwner) if caller
/// is not the current owner.
pub fn change_ownership(&mut self, owner: Address) {
self.owner.ensure_owner();
self.owner.change_ownership(owner);
self.whitelist.add_to_whitelist(owner);
}

/// Adds a new address to the whitelist.
///
/// # Errors
Expand Down
3 changes: 0 additions & 3 deletions dao/src/utils_contracts/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ impl DaoIdsContract {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// [`Read more`](crate::modules::access_control::AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract to the new address.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
///
/// [`Read more`](AccessControl::add_to_whitelist())
Expand Down
4 changes: 0 additions & 4 deletions dao/src/voting_contracts/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl AdminContract {
to self.access_control {
pub fn propose_new_owner(&mut self, owner: Address);
pub fn accept_new_owner(&mut self);
pub fn change_ownership(&mut self, owner: Address);
pub fn add_to_whitelist(&mut self, address: Address);
pub fn remove_from_whitelist(&mut self, address: Address);
pub fn is_whitelisted(&self, address: Address) -> bool;
Expand Down Expand Up @@ -180,7 +179,6 @@ impl AdminVotingCreated {
pub enum Action {
AddToWhitelist,
RemoveFromWhitelist,
ChangeOwnership,
ProposeNewOwner,
}

Expand All @@ -189,7 +187,6 @@ impl Action {
match self {
Action::AddToWhitelist => "add_to_whitelist",
Action::RemoveFromWhitelist => "remove_from_whitelist",
Action::ChangeOwnership => "change_ownership",
Action::ProposeNewOwner => "propose_new_owner",
}
.to_string()
Expand All @@ -199,7 +196,6 @@ impl Action {
match self {
Action::AddToWhitelist => "address",
Action::RemoveFromWhitelist => "address",
Action::ChangeOwnership => "owner",
Action::ProposeNewOwner => "owner",
}
}
Expand Down
1 change: 0 additions & 1 deletion dao/src/voting_contracts/kyc_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl KycVoterContract {
to self.access_control {
pub fn propose_new_owner(&mut self, owner: Address);
pub fn accept_new_owner(&mut self);
pub fn change_ownership(&mut self, owner: Address);
pub fn add_to_whitelist(&mut self, address: Address);
pub fn remove_from_whitelist(&mut self, address: Address);
pub fn is_whitelisted(&self, address: Address) -> bool;
Expand Down
3 changes: 0 additions & 3 deletions dao/src/voting_contracts/onboarding_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ impl OnboardingRequestContract {
/// Accepts the new owner proposition. This can be called only by the proposed owner.
/// [`Read more`](AccessControl::accept_new_owner())
pub fn accept_new_owner(&mut self);
/// Changes the ownership of the contract. Transfers ownership to the `owner`.
/// [`Read more`](AccessControl::change_ownership())
pub fn change_ownership(&mut self, owner: Address);
/// Adds a new address to the whitelist.
/// [`Read more`](AccessControl::add_to_whitelist())
pub fn add_to_whitelist(&mut self, address: Address);
Expand Down
1 change: 0 additions & 1 deletion dao/src/voting_contracts/repo_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl RepoVoterContract {
to self.access_control {
pub fn propose_new_owner(&mut self, owner: Address);
pub fn accept_new_owner(&mut self);
pub fn change_ownership(&mut self, owner: Address);
pub fn add_to_whitelist(&mut self, address: Address);
pub fn remove_from_whitelist(&mut self, address: Address);
pub fn is_whitelisted(&self, address: Address) -> bool;
Expand Down
1 change: 0 additions & 1 deletion dao/src/voting_contracts/reputation_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl ReputationVoterContract {
to self.access_control {
pub fn propose_new_owner(&mut self, owner: Address);
pub fn accept_new_owner(&mut self);
pub fn change_ownership(&mut self, owner: Address);
pub fn add_to_whitelist(&mut self, address: Address);
pub fn remove_from_whitelist(&mut self, address: Address);
pub fn is_whitelisted(&self, address: Address) -> bool;
Expand Down
1 change: 0 additions & 1 deletion dao/src/voting_contracts/simple_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl SimpleVoterContract {
to self.access_control {
pub fn propose_new_owner(&mut self, owner: Address);
pub fn accept_new_owner(&mut self);
pub fn change_ownership(&mut self, owner: Address);
pub fn add_to_whitelist(&mut self, address: Address);
pub fn remove_from_whitelist(&mut self, address: Address);
pub fn is_whitelisted(&self, address: Address) -> bool;
Expand Down
1 change: 0 additions & 1 deletion dao/src/voting_contracts/slashing_voter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ impl SlashingVoterContract {
to self.access_control {
pub fn propose_new_owner(&mut self, owner: Address);
pub fn accept_new_owner(&mut self);
pub fn change_ownership(&mut self, owner: Address);
pub fn add_to_whitelist(&mut self, address: Address);
pub fn remove_from_whitelist(&mut self, address: Address);
pub fn is_whitelisted(&self, address: Address) -> bool;
Expand Down
9 changes: 9 additions & 0 deletions dao/tests/common/contracts/ownership.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use dao::utils::Error::NoProposedOwner;
use odra::test_env;
use odra::types::address::OdraAddress;
use odra::types::Address;

Expand Down Expand Up @@ -69,6 +71,13 @@ impl DaoWorld {
AccessControlRef::at(&contract).accept_new_owner();
}

pub fn accept_new_owner_fails(&mut self, contract: &Account) {
let contract = self.get_address(contract);
test_env::assert_exception(NoProposedOwner, || {
AccessControlRef::at(&contract).accept_new_owner()
});
}

pub fn accept_new_owner_as_contract(&mut self, contract: &Account, new_owner: &Account) {
let new_owner = self.get_address(new_owner);
let contract = self.get_address(contract);
Expand Down
2 changes: 1 addition & 1 deletion dao/tests/common/contracts/voting/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn build(world: &DaoWorld, voting: Voting) -> VotingSetup {
let action = match action.as_str() {
"add_to_whitelist" => AdminAction::AddToWhitelist,
"remove_from_whitelist" => AdminAction::RemoveFromWhitelist,
"change_ownership" => AdminAction::ChangeOwnership,
"propose_new_owner" => AdminAction::ProposeNewOwner,
unknown => panic!("{:?} is not a valid action", unknown),
};

Expand Down
4 changes: 2 additions & 2 deletions dao/tests/features/voting/admin/admin_actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Scenario Outline: Voting passed, action applied
| action | subject | result |
| add_to_whitelist | Alice | is whitelisted in ReputationToken contract |
| remove_from_whitelist | Bob | is not whitelisted in ReputationToken contract |
| change_ownership | Bob | is the owner of ReputationToken contract |
| propose_new_owner | Bob | is the proposed owner of ReputationToken contract |

Scenario Outline: Voting rejected, action not applied
When Admin voting with id 0 created by VA1 fails
Expand All @@ -34,4 +34,4 @@ Scenario Outline: Voting rejected, action not applied
| action | subject | result |
| add_to_whitelist | Alice | is not whitelisted in ReputationToken contract |
| remove_from_whitelist | Bob | is whitelisted in ReputationToken contract |
| change_ownership | Bob | is not the owner of ReputationToken contract |
| propose_new_owner | Bob | is not the proposed owner of ReputationToken contract |
9 changes: 9 additions & 0 deletions dao/tests/steps/ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ fn assert_ne_ownership(world: &mut DaoWorld, user: Account, contract: Account) {

assert_ne!(owner, Some(user_address));
}

#[then(expr = "{account} is not the proposed owner of {account} contract")]
fn assert_not_proposed_ownership(world: &mut DaoWorld, user: Account, contract: Account) {
let user_address = world.get_address(&user);
world.set_caller(&user);
world.accept_new_owner_fails(&contract);
let owner = world.get_owner(&contract);
assert_ne!(owner, Some(user_address));
}
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
BINARYEN_VERSION := "version_116"
BINARYEN_CHECKSUM := "c55b74f3109cdae97490faf089b0286d3bba926bb6ea5ed00c8c784fc53718fd"

prepare:
rustup target add wasm32-unknown-unknown
cargo install --version 0.0.9-fixed --force --locked cargo-odra
wget https://github.com/WebAssembly/binaryen/releases/download/{{BINARYEN_VERSION}}/binaryen-{{BINARYEN_VERSION}}-x86_64-linux.tar.gz || { echo "Download failed"; exit 1; }
sha256sum binaryen-{{BINARYEN_VERSION}}-x86_64-linux.tar.gz | grep {{BINARYEN_CHECKSUM}} || { echo "Checksum verification failed"; exit 1; }
tar -xzf binaryen-{{BINARYEN_VERSION}}-x86_64-linux.tar.gz || { echo "Extraction failed"; exit 1; }
sudo cp binaryen-{{BINARYEN_VERSION}}/bin/wasm-opt /usr/local/bin/wasm-opt

build-dao-contracts:
cargo odra build -b casper
Expand Down
11 changes: 0 additions & 11 deletions resources/admin_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/bid_escrow_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/dao_ids_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/kyc_nft_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/kyc_voter_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/onboarding_request_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/repo_voter_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
11 changes: 0 additions & 11 deletions resources/reputation_contract_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@
"args": [],
"return_ty": "Unit"
},
{
"name": "change_ownership",
"is_mutable": true,
"args": [
{
"name": "owner",
"ty": "Key"
}
],
"return_ty": "Unit"
},
{
"name": "add_to_whitelist",
"is_mutable": true,
Expand Down
Loading

0 comments on commit caef09a

Please sign in to comment.