Skip to content

Commit

Permalink
[Native bridge move] tests for msg encoding and some changes (#16216)
Browse files Browse the repository at this point in the history
  • Loading branch information
longbowlu authored and patrickkuo committed Feb 26, 2024
1 parent 58c8570 commit 7de8446
Show file tree
Hide file tree
Showing 13 changed files with 1,180 additions and 183 deletions.
285 changes: 227 additions & 58 deletions crates/sui-framework/docs/bridge/bridge.md

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion crates/sui-framework/docs/bridge/btc.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@



<a name="0xb_btc_EDecimalMultiplierMismatch"></a>



<pre><code><b>const</b> <a href="btc.md#0xb_btc_EDecimalMultiplierMismatch">EDecimalMultiplierMismatch</a>: u64 = 0;
</code></pre>



<a name="0xb_btc_MULTIPLIER"></a>

Multiplier of the token, it must be 10^DECIMAL


<pre><code><b>const</b> <a href="btc.md#0xb_btc_MULTIPLIER">MULTIPLIER</a>: u64 = 100000000;
</code></pre>



<a name="0xb_btc_create"></a>

## Function `create`
Expand All @@ -79,6 +98,7 @@


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="btc.md#0xb_btc_create">create</a>(ctx: &<b>mut</b> TxContext): TreasuryCap&lt;<a href="btc.md#0xb_btc_BTC">BTC</a>&gt; {
<b>assert</b>!(<a href="btc.md#0xb_btc_MULTIPLIER">MULTIPLIER</a> == pow(10, <a href="btc.md#0xb_btc_DECIMAL">DECIMAL</a>), <a href="btc.md#0xb_btc_EDecimalMultiplierMismatch">EDecimalMultiplierMismatch</a>);
<b>let</b> (treasury_cap, metadata) = <a href="dependencies/sui-framework/coin.md#0x2_coin_create_currency">coin::create_currency</a>(
<a href="btc.md#0xb_btc_BTC">BTC</a> {},
<a href="btc.md#0xb_btc_DECIMAL">DECIMAL</a>,
Expand Down Expand Up @@ -137,7 +157,7 @@


<pre><code><b>public</b> <b>fun</b> <a href="btc.md#0xb_btc_multiplier">multiplier</a>(): u64 {
pow(10, <a href="btc.md#0xb_btc_DECIMAL">DECIMAL</a>)
<a href="btc.md#0xb_btc_MULTIPLIER">MULTIPLIER</a>
}
</code></pre>

Expand Down
91 changes: 86 additions & 5 deletions crates/sui-framework/docs/bridge/chain_ids.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- [Function `eth_mainnet`](#0xb_chain_ids_eth_mainnet)
- [Function `eth_sepolia`](#0xb_chain_ids_eth_sepolia)
- [Function `eth_local_test`](#0xb_chain_ids_eth_local_test)
- [Function `route_source`](#0xb_chain_ids_route_source)
- [Function `route_destination`](#0xb_chain_ids_route_destination)
- [Function `assert_valid_chain_id`](#0xb_chain_ids_assert_valid_chain_id)
- [Function `valid_routes`](#0xb_chain_ids_valid_routes)
- [Function `is_valid_route`](#0xb_chain_ids_is_valid_route)
- [Function `get_route`](#0xb_chain_ids_get_route)
Expand Down Expand Up @@ -300,6 +303,87 @@



</details>

<a name="0xb_chain_ids_route_source"></a>

## Function `route_source`



<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_route_source">route_source</a>(route: &<a href="chain_ids.md#0xb_chain_ids_BridgeRoute">chain_ids::BridgeRoute</a>): &u8
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_route_source">route_source</a>(route: &<a href="chain_ids.md#0xb_chain_ids_BridgeRoute">BridgeRoute</a>): &u8 {
&route.source
}
</code></pre>



</details>

<a name="0xb_chain_ids_route_destination"></a>

## Function `route_destination`



<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_route_destination">route_destination</a>(route: &<a href="chain_ids.md#0xb_chain_ids_BridgeRoute">chain_ids::BridgeRoute</a>): &u8
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_route_destination">route_destination</a>(route: &<a href="chain_ids.md#0xb_chain_ids_BridgeRoute">BridgeRoute</a>): &u8 {
&route.destination
}
</code></pre>



</details>

<a name="0xb_chain_ids_assert_valid_chain_id"></a>

## Function `assert_valid_chain_id`



<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_assert_valid_chain_id">assert_valid_chain_id</a>(id: u8)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_assert_valid_chain_id">assert_valid_chain_id</a>(id: u8) {
<b>assert</b>!(
id == <a href="chain_ids.md#0xb_chain_ids_SuiMainnet">SuiMainnet</a> ||
id == <a href="chain_ids.md#0xb_chain_ids_SuiTestnet">SuiTestnet</a> ||
id == <a href="chain_ids.md#0xb_chain_ids_SuiDevnet">SuiDevnet</a> ||
id == <a href="chain_ids.md#0xb_chain_ids_SuiLocalTest">SuiLocalTest</a> ||
id == <a href="chain_ids.md#0xb_chain_ids_EthMainnet">EthMainnet</a> ||
id == <a href="chain_ids.md#0xb_chain_ids_EthSepolia">EthSepolia</a> ||
id == <a href="chain_ids.md#0xb_chain_ids_EthLocalTest">EthLocalTest</a>,
<a href="chain_ids.md#0xb_chain_ids_EInvalidBridgeRoute">EInvalidBridgeRoute</a>
)
}
</code></pre>



</details>

<a name="0xb_chain_ids_valid_routes"></a>
Expand Down Expand Up @@ -384,11 +468,8 @@

<pre><code><b>public</b> <b>fun</b> <a href="chain_ids.md#0xb_chain_ids_get_route">get_route</a>(source: u8, destination: u8): <a href="chain_ids.md#0xb_chain_ids_BridgeRoute">BridgeRoute</a> {
<b>let</b> route = <a href="chain_ids.md#0xb_chain_ids_BridgeRoute">BridgeRoute</a> { source, destination };
<b>return</b> <b>if</b> (<a href="dependencies/move-stdlib/vector.md#0x1_vector_contains">vector::contains</a>(&<a href="chain_ids.md#0xb_chain_ids_valid_routes">valid_routes</a>(), &route)) {
route
} <b>else</b> {
<b>abort</b> <a href="chain_ids.md#0xb_chain_ids_EInvalidBridgeRoute">EInvalidBridgeRoute</a>
}
<b>assert</b>!(<a href="dependencies/move-stdlib/vector.md#0x1_vector_contains">vector::contains</a>(&<a href="chain_ids.md#0xb_chain_ids_valid_routes">valid_routes</a>(), &route), <a href="chain_ids.md#0xb_chain_ids_EInvalidBridgeRoute">EInvalidBridgeRoute</a>);
route
}
</code></pre>

Expand Down
22 changes: 21 additions & 1 deletion crates/sui-framework/docs/bridge/eth.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@



<a name="0xb_eth_EDecimalMultiplierMismatch"></a>



<pre><code><b>const</b> <a href="eth.md#0xb_eth_EDecimalMultiplierMismatch">EDecimalMultiplierMismatch</a>: u64 = 0;
</code></pre>



<a name="0xb_eth_MULTIPLIER"></a>

Multiplier of the token, it must be 10^DECIMAL


<pre><code><b>const</b> <a href="eth.md#0xb_eth_MULTIPLIER">MULTIPLIER</a>: u64 = 100000000;
</code></pre>



<a name="0xb_eth_create"></a>

## Function `create`
Expand All @@ -79,6 +98,7 @@


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="eth.md#0xb_eth_create">create</a>(ctx: &<b>mut</b> TxContext): TreasuryCap&lt;<a href="eth.md#0xb_eth_ETH">ETH</a>&gt; {
<b>assert</b>!(<a href="eth.md#0xb_eth_MULTIPLIER">MULTIPLIER</a> == pow(10, <a href="eth.md#0xb_eth_DECIMAL">DECIMAL</a>), <a href="eth.md#0xb_eth_EDecimalMultiplierMismatch">EDecimalMultiplierMismatch</a>);
<b>let</b> (treasury_cap, metadata) = <a href="dependencies/sui-framework/coin.md#0x2_coin_create_currency">coin::create_currency</a>(
<a href="eth.md#0xb_eth_ETH">ETH</a> {},
<a href="eth.md#0xb_eth_DECIMAL">DECIMAL</a>,
Expand Down Expand Up @@ -137,7 +157,7 @@


<pre><code><b>public</b> <b>fun</b> <a href="eth.md#0xb_eth_multiplier">multiplier</a>(): u64 {
pow(10, <a href="eth.md#0xb_eth_DECIMAL">DECIMAL</a>)
<a href="eth.md#0xb_eth_MULTIPLIER">MULTIPLIER</a>
}
</code></pre>

Expand Down
Loading

0 comments on commit 7de8446

Please sign in to comment.