Skip to content

Commit

Permalink
feat: implement set_shvt_staking() with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienCoutant committed Dec 6, 2023
1 parent 77b90f8 commit 21f5cda
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/address_provider.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod AddressProvider {
fn set_shvt_staking(ref self: ContractState, _shvt_staking: ContractAddress) {
self.ownable.assert_only_owner();
self.assert_not_address_zero(_shvt_staking);
self.community_issuance.write(_shvt_staking);
self.shvt_staking.write(_shvt_staking);
}

fn get_active_pool(ref self: ContractState) -> ContractAddress {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
use starknet::{ContractAddress, contract_address_const};
use snforge_std::{start_prank, CheatTarget};
use shisui::core::address_provider::{IAddressProviderDispatcher, IAddressProviderDispatcherTrait};

fn setup() -> (IAddressProviderDispatcher, ContractAddress) {
let contract_address: ContractAddress = tests::tests_lib::deploy_address_provider();
let address_provider: IAddressProviderDispatcher = IAddressProviderDispatcher {
contract_address
};
(address_provider, contract_address)
}


// This tests check that not owner can't call the function
// It calls address_provider.set_shvt_staking()
// The test expects the call to revert
#[test]
#[should_panic(expected: ('Caller is not the owner',))]
fn given_caller_is_not_owner_it_should_revert() {
let (address_provider, address_provider_address) = setup();

start_prank(
CheatTarget::One(address_provider_address), contract_address_const::<'not_owner'>()
);

address_provider.set_shvt_staking(contract_address_const::<0x1>());
}


// This tests check that no address zero is allowed
// It calls address_provider.set_shvt_staking()
// The test expects the call to revert
#[test]
#[should_panic(expected: ('Address is zero',))]
fn given_caller_is_owner_and_at_least_one_address_is_zero_it_should_revert() {
let (address_provider, address_provider_address) = setup();
address_provider.set_shvt_staking(contract_address_const::<0x0>());
}

// This tests check that contract owner can set addresses
// It calls address_provider.set_shvt_staking()
#[test]
fn given_caller_is_owner_it_should_set_shvt_staking() {
let (address_provider, address_provider_address) = setup();
let shvt_staking: ContractAddress = contract_address_const::<0x1>();
address_provider.set_shvt_staking(shvt_staking);
assert(address_provider.get_shvt_staking() == shvt_staking, 'SHVT staking not correct');
}

0 comments on commit 21f5cda

Please sign in to comment.