Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Test/trex gateway #81

wants to merge 7 commits into from

Conversation

EgeCaner
Copy link
Collaborator

No description provided.

@EgeCaner EgeCaner linked an issue Jan 22, 2025 that may be closed by this pull request
@EgeCaner EgeCaner marked this pull request as ready for review January 22, 2025 12:39
Copy link
Member

@julio4 julio4 left a 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(),
Copy link
Member

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?

Comment on lines +189 to +209
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,
},
),
),
],
);
}
Copy link
Member

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.

Suggested change
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
}

Comment on lines +230 to +241
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',
);
}
}
Copy link
Member

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 },
Copy link
Member

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

Comment on lines +331 to +333
let fee_collector = starknet::contract_address_const::<'FEE_COLLECTOR'>();
let fee_token = setup.token.contract_address;
let fee = 100;
Copy link
Member

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)

Comment on lines +443 to +447
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, suggest:

Suggested change
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() {
Copy link
Member

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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');
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gateway Test
2 participants