-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test/trex gateway #81
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Really minor changes and should be ready
@array![ | ||
setup.trex_factory.contract_address.into(), | ||
public_deployment_status.into(), | ||
starknet::get_contract_address().into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TREXGateway needs to have the third arg starknet::get_contract_address()
?
Is it not always the same, why not setting it as the caller in gateway contract?
fn test_should_set_new_status(status_u8: u8) { | ||
let status = status_u8 % 2 == 0; | ||
let (_, gateway) = setup_gateway(status); | ||
let mut spy = spy_events(); | ||
|
||
gateway.set_public_deployment_status(!status); | ||
assert(gateway.get_public_deployment_status() == !status, 'Status didnt changed'); | ||
spy | ||
.assert_emitted( | ||
@array![ | ||
( | ||
gateway.contract_address, | ||
TREXGateway::Event::PublicDeploymentStatusSet( | ||
TREXGateway::PublicDeploymentStatusSet { | ||
public_deployment_status: !status, | ||
}, | ||
), | ||
), | ||
], | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if fuzz testing is the best here, especially because there's no bool support.
fn test_should_set_new_status(status_u8: u8) { | |
let status = status_u8 % 2 == 0; | |
let (_, gateway) = setup_gateway(status); | |
let mut spy = spy_events(); | |
gateway.set_public_deployment_status(!status); | |
assert(gateway.get_public_deployment_status() == !status, 'Status didnt changed'); | |
spy | |
.assert_emitted( | |
@array![ | |
( | |
gateway.contract_address, | |
TREXGateway::Event::PublicDeploymentStatusSet( | |
TREXGateway::PublicDeploymentStatusSet { | |
public_deployment_status: !status, | |
}, | |
), | |
), | |
], | |
); | |
} | |
fn test_should_set_new_status() { | |
let (_, gateway) = setup_gateway(false); | |
let mut spy = spy_events(); | |
gateway.set_public_deployment_status(true); | |
assert!(gateway.get_public_deployment_status(), 'Status didnt changed'); | |
spy | |
.assert_emitted( | |
@array![ | |
( | |
gateway.contract_address, | |
TREXGateway::Event::PublicDeploymentStatusSet( | |
TREXGateway::PublicDeploymentStatusSet { | |
public_deployment_status: !status, | |
}, | |
), | |
), | |
], | |
); | |
// Optionally: test gateway.set_public_deployment_status(false) again | |
} |
fn test_should_transfer_factory_ownership() { | ||
let (setup, gateway) = setup_gateway(false); | ||
|
||
let new_owner = starknet::contract_address_const::<'SOME_ADDRESS'>(); | ||
gateway.transfer_factory_ownership(new_owner); | ||
assert( | ||
IOwnableDispatcher { contract_address: setup.trex_factory.contract_address } | ||
.owner() == new_owner, | ||
'Ownership didnt transferred', | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test for OwnershipTransferred emit event
( | ||
gateway.contract_address, | ||
TREXGateway::Event::DeploymentFeeEnabled( | ||
TREXGateway::DeploymentFeeEnabled { is_enabled: false }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeploymentFeeEnabled
is really not a good event name if it's also emitted when disabling, but yeah let's keep same name as trex
let fee_collector = starknet::contract_address_const::<'FEE_COLLECTOR'>(); | ||
let fee_token = setup.token.contract_address; | ||
let fee = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider moving any const values in top of set_deployment_fee module (same for other modules)
let deployer = setup.accounts.alice.account.contract_address; | ||
let mut spy = spy_events(); | ||
|
||
start_cheat_caller_address( | ||
gateway.contract_address, setup.accounts.token_agent.account.contract_address, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, suggest:
let deployer = setup.accounts.alice.account.contract_address; | |
let mut spy = spy_events(); | |
start_cheat_caller_address( | |
gateway.contract_address, setup.accounts.token_agent.account.contract_address, | |
let deployer = setup.accounts.alice.account.contract_address; | |
let agent = setup.accounts.token_agent.account.contract_address; | |
let mut spy = spy_events(); | |
start_cheat_caller_address( | |
gateway.contract_address, agent, |
}; | ||
deployers.append(deployer); | ||
// When batch has registered deployer should revert the whole batch | ||
gateway.batch_add_deployer([deployer].span()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gateway.batch_add_deployer([deployer].span()); | |
gateway.batch_add_deployer(deployers.span()); |
|
||
#[test] | ||
#[should_panic(expected: 'Deployer already exists')] | ||
fn test_should_panic_when_called_by_agent_when_batch_includes_already_registered_deployer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, is it necessary? We have test_should_panic_when_called_by_owner_when_batch_includes_already_registered_deployer
}; | ||
deployers.append(deployer); | ||
// When batch has registered deployer should revert the whole batch | ||
gateway.batch_add_deployer([deployer].span()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gateway.batch_add_deployer([deployer].span()); | |
gateway.batch_add_deployer(deployers.span()); |
@setup, gateway, ref spy, token_details, not_deployer, 20_000, | ||
); | ||
/// Check token transfer | ||
assert(fee_token.balance_of(fee_collector) == 20_000, 'Fee not transferred'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also assert balance of not_deployer
== 80_000
No description provided.