-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(interchain-token-service): add flow limit #130
Conversation
- implement flow limit for interchain transfers - add Operatable trait and change constructor - update golden files (tests generate different contract addresses due to updated constructor) - minor changes to test helper functions
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #130 +/- ##
==========================================
+ Coverage 94.63% 94.84% +0.20%
==========================================
Files 52 53 +1
Lines 3130 3276 +146
==========================================
+ Hits 2962 3107 +145
- Misses 168 169 +1 ☔ View full report in Codecov by Sentry. |
- Add docstrings to entrypoints - Create FlowKey struct for better organization of storage keys - Move flow logic into FlowDirection impl - Organize imports and group public functions - Allow zero flow limit to 'freeze' token
- encapsulate add flow logic in Flow Direction enum - add comments/docstring where necessary - move entrypoint docstring from contract to interface - refactor imports
- improve docstring describing flow direction - remove unneeded variables in add_flow
const TEST_FLOW_LIMIT: Option<i128> = Some(1000); | ||
const EPOCH_TIME: u64 = 6 * 60 * 60; | ||
|
||
fn setup_flow_limit(env: &Env, client: &InterchainTokenServiceClient) -> (BytesN<32>, 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.
fn setup_flow_limit(env: &Env, client: &InterchainTokenServiceClient) -> (BytesN<32>, Address) { | |
fn setup(env: &Env, client: &InterchainTokenServiceClient) -> (BytesN<32>, Address) { |
perhaps
client: &InterchainTokenServiceClient, | ||
token_id: &BytesN<32>, | ||
amount: i128, | ||
) -> (String, String, String, Bytes, Vec<GatewayMessage>) { |
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.
) -> (String, String, String, Bytes, Vec<GatewayMessage>) { | |
) -> TestMessage { |
create a struct
(token_id, deployer) | ||
} | ||
|
||
fn create_interchain_transfer_message( |
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.
fn create_interchain_transfer_message( | |
fn execute_its_transfer( |
perhaps. It can approve and execute ITS in the helper itself to reduce duplication
payload_hash, | ||
}, | ||
]; | ||
|
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.
call approve gateway within this method to reduce duplication
let recipient = Address::generate(env).to_xdr(env); | ||
let source_chain = client.its_hub_chain_name(); | ||
let source_address = Address::generate(env).to_string(); | ||
|
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.
let message_id = Address::generate(env).to_string(); | |
let gas_token = setup_gas_token(&env, &sender); | ||
|
||
let amount = 1000; | ||
let destination_chain = String::from_str(&env, "ethereum"); |
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.
create a helper for these dummy values
.mock_all_auths() | ||
.set_trusted_chain(&destination_chain); | ||
|
||
client.mock_all_auths().interchain_transfer( |
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 comment on hard to tell which call panicked, so use assert_auth_ok here
let (token_id, sender) = setup_flow_limit(&env, &client); | ||
let gas_token = setup_gas_token(&env, &sender); | ||
|
||
client |
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.
client | |
let flow_limit = i128::MAX - 50; | |
client |
.mock_all_auths() | ||
.set_flow_limit(&token_id, &Some(i128::MAX - 50)); | ||
|
||
let high_amount = i128::MAX - 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.
let high_amount = i128::MAX - 100; | |
let high_amount = flow_limit - 1; |
reuse value
approve_gateway_messages(&env, &gateway_client, signers, messages); | ||
client.execute(&source_chain, &message_id, &source_address, &payload); | ||
|
||
let small_amount = 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.
let small_amount = 100; | |
let small_amount = 2; |
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.
I recommend creating a vector of flow in + flow out test cases, and running the test logic here in a loop over them to try different scenarios
AXE-6087