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

Bridge test env #17941

Merged
merged 1 commit into from
Jun 1, 2024
Merged

Bridge test env #17941

merged 1 commit into from
Jun 1, 2024

Conversation

dariorussi
Copy link
Contributor

@dariorussi dariorussi commented May 26, 2024

Description

Increase test coverage and create a test environment for the bridge that should make it easier to test.
At this point once we have API to sign messages we can reach 100% coverage. All missing tests are related to signature generation, function depending on that, or versioning. API to sign messages and create pub/priv keys are coming that would allow us to create a great testing environment and experience.
Current coverage is as follows

+-------------------------+
| Move Coverage Summary   |
+-------------------------+
Module 000000000000000000000000000000000000000000000000000000000000000b::treasury
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::message_types
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::chain_ids
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::message
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::limiter
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::crypto
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::committee
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::bridge
>>> % Module coverage: 51.21
+-------------------------+
| % Move Coverage: 82.32  |
+-------------------------+

The test environment needs more work but it will come in time. For now this work was mostly to reach a good test coverage.
It's important to check this in for 2 main reasons: it increases test coverage significantly and allows others to work on it and improve it.

Test plan

This is it


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented May 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 1, 2024 7:55am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jun 1, 2024 7:55am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jun 1, 2024 7:55am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Jun 1, 2024 7:55am

Copy link
Contributor

@longbowlu longbowlu left a comment

Choose a reason for hiding this comment

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

overall lgtm!

scenario.next_tx(@0xAAAA);
let mut bridge = scenario.take_shared<Bridge>();
bridge.send_token(target_chain_id, eth_address, coin, scenario.ctx());
test_scenario::return_shared(bridge);
Copy link
Contributor

Choose a reason for hiding this comment

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

we can check a few things here:

  1. assert the burn happened
  2. token_transfer_records has a new entry with correct metadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

scenario.next_tx(sender);
let mut bridge = scenario.take_shared<Bridge>();
bridge.register_foreign_token<T>(treasury_cap, upgrade_cap, &metadata);
test_scenario::return_shared(bridge);
Copy link
Contributor

Choose a reason for hiding this comment

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

check waiting_room and treasuries have proper changes here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// scenario.end();
// }
#[test]
fun test_register_foreign_token() {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. do we have a test case for coin::total_supply(&tc) != 0?
    https://github.com/MystenLabs/sui/blob/main/crates/sui-framework/packages/bridge/sources/treasury.move#L103

  2. do we have some test cases for add_new_token?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. test_register_foreign_token_non_zero_supply
  2. add_default_tokens to set up the default token does that for the happy path every time you set up the bridge and test_add_token_price_zero_value, test_add_token_malformed_1, test_add_token_malformed_2, test_add_token_malformed_3 and test_add_native_token_nop test the not so happy path

@dariorussi
Copy link
Contributor Author

thanks @longbowlu for the review and added the assert checks into some of the function. That is a good idea.
I'll look into more that we can do there as those are good checks for the environment.
So more coming though at this point I'd rather have this in and iterate.
Anyway take a look

Copy link
Contributor

@longbowlu longbowlu left a comment

Choose a reason for hiding this comment

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

thanks!

@dariorussi dariorussi merged commit 9d6fec6 into main Jun 1, 2024
44 checks passed
@dariorussi dariorussi deleted the bridge_test_env branch June 1, 2024 10:23
tx-tomcat pushed a commit to tx-tomcat/sui-network that referenced this pull request Jul 29, 2024
## Description 

Increase test coverage and create a test environment for the bridge that
should make it easier to test.
At this point once we have API to sign messages we can reach 100%
coverage. All missing tests are related to signature generation,
function depending on that, or versioning. API to sign messages and
create pub/priv keys are coming that would allow us to create a great
testing environment and experience.
Current coverage is as follows
```
+-------------------------+
| Move Coverage Summary   |
+-------------------------+
Module 000000000000000000000000000000000000000000000000000000000000000b::treasury
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::message_types
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::chain_ids
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::message
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::limiter
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::crypto
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::committee
>>> % Module coverage: 100.00
Module 000000000000000000000000000000000000000000000000000000000000000b::bridge
>>> % Module coverage: 51.21
+-------------------------+
| % Move Coverage: 82.32  |
+-------------------------+
```

The test environment needs more work but it will come in time. For now
this work was mostly to reach a good test coverage.
It's important to check this in for 2 main reasons: it increases test
coverage significantly and allows others to work on it and improve it.

## Test plan 

This is it

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
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.

2 participants