Skip to content

Commit

Permalink
Merge branch 'lf/feat/update-beta-5' of github.com:FuelLabs/fuel-brid…
Browse files Browse the repository at this point in the history
…ge into lf/feat/update-beta-5
  • Loading branch information
LuizAsFight committed Dec 13, 2023
2 parents 3bfd90d + 65eb6cf commit 97a7b26
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 115 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions fuel-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "latest-2023-11-30"

[components]
forc = "0.48.1"
6 changes: 3 additions & 3 deletions packages/fungible-token/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center">
<a href="https://crates.io/crates/forc/0.48.0" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.48.0-orange" />
<a href="https://crates.io/crates/forc/0.48.1" alt="forc">
<img src="https://img.shields.io/badge/forc-v0.48.1-orange" />
</a>
<a href="https://crates.io/crates/fuel-core/0.21.0" alt="fuel-core">
<a href="https://crates.io/crates/fuel-core/0.22.0" alt="fuel-core">
<img src="https://img.shields.io/badge/fuel--core-v0.21.0-blue" />
</a>
</p>
Expand Down
1 change: 1 addition & 0 deletions packages/fungible-token/bridge-fungible-token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ publish = false
fuel-core-types = { workspace = true }
# Dependencies from fuels-rs repository:
fuels = { workspace = true, features = ["fuel-core-lib"] }
hex = "0.4.3"

primitive-types = "0.12.1"
sha3 = "0.10.1"
Expand Down
8 changes: 5 additions & 3 deletions packages/fungible-token/bridge-fungible-token/src/utils.sw
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ fn shift_decimals_right(bn: u256, decimals: u8) -> Result<u256, BridgeFungibleTo
return Result::Err(BridgeFungibleTokenError::UnderflowError);
}

let remainder = bn_clone % (TEN.pow(decimals_to_shift));
let base = TEN.pow(decimals_to_shift);
let adjusted = bn_clone / (TEN.pow(decimals_to_shift));
let check = (bn_clone + base - 0x01_u256) / base;

if remainder != ZERO_B256.as_u256() {
// TODO: Convoluted way of checking modulo, workaround for modulo issues around u256
if check != adjusted {
return Result::Err(BridgeFungibleTokenError::UnderflowError);
}
let adjusted = bn_clone / (TEN.pow(decimals_to_shift));

return Result::Ok(adjusted)
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod success {
.unwrap();

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -217,14 +217,13 @@ mod success {

dbg!(&receipts);


let refund_registered_event = bridge
.log_decoder()
.decode_logs_with_type::<RefundRegisteredEvent>(&receipts)
.unwrap();

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -354,7 +353,7 @@ mod success {
}

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

let expected_deposited_amount = config.fuel_equivalent_amount(config.amount.max);
Expand Down Expand Up @@ -450,8 +449,18 @@ mod success {
)
.await;

let receipts = provider.tx_status(&_tx_id).await.unwrap().take_receipts();

dbg!(&receipts);

for receipt in receipts {
if let Receipt::LogData { data, .. } = receipt {
dbg!(hex::encode(data.unwrap()));
}
}

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -593,7 +602,7 @@ mod revert {
.await;

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -643,7 +652,7 @@ mod revert {
configurables,
)
.await;

bridge
.methods()
.asset_to_sub_id(AssetId::from_str(incorrect_asset_id).unwrap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod success {
.await;

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge
Expand Down Expand Up @@ -113,7 +113,7 @@ mod success {
.await;

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -186,7 +186,7 @@ mod success {
.await;

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &asset_id).await;

// Verify the message value was received by the bridge
Expand Down Expand Up @@ -280,7 +280,7 @@ mod success {
.await;

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &asset_id).await;

// Verify the message value was received by the bridge
Expand Down Expand Up @@ -385,7 +385,7 @@ mod success {

// Get the balance for the deposit contract before
let deposit_contract_balance_before =
contract_balance(&provider, deposit_contract.contract_id(), asset_id).await;
contract_balance(provider, deposit_contract.contract_id(), asset_id).await;

// Relay the test message to the bridge contract
let _receipts = relay_message_to_contract(
Expand All @@ -397,7 +397,7 @@ mod success {

// Get the balance for the deposit contract after
let deposit_contract_balance_after =
contract_balance(&provider, deposit_contract.contract_id(), asset_id).await;
contract_balance(provider, deposit_contract.contract_id(), asset_id).await;

assert_eq!(
deposit_contract_balance_after,
Expand Down Expand Up @@ -453,7 +453,7 @@ mod success {

// Get the balance for the deposit contract after
let deposit_contract_balance_after =
contract_balance(&provider, deposit_contract.contract_id(), asset_id).await;
contract_balance(provider, deposit_contract.contract_id(), asset_id).await;

assert_eq!(
deposit_contract_balance_after,
Expand Down Expand Up @@ -509,7 +509,7 @@ mod success {

// Get the balance for the deposit contract after
let deposit_contract_balance_after =
contract_balance(&provider, deposit_contract.contract_id(), asset_id).await;
contract_balance(provider, deposit_contract.contract_id(), asset_id).await;

assert_eq!(
deposit_contract_balance_after,
Expand Down Expand Up @@ -565,7 +565,7 @@ mod success {

// Get the balance for the deposit contract after
let deposit_contract_balance_after =
contract_balance(&provider, deposit_contract.contract_id(), asset_id).await;
contract_balance(provider, deposit_contract.contract_id(), asset_id).await;

assert_eq!(
deposit_contract_balance_after,
Expand Down Expand Up @@ -633,7 +633,7 @@ mod success {
.unwrap();

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -709,7 +709,7 @@ mod success {
.unwrap();

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -785,7 +785,7 @@ mod success {
.unwrap();

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -861,7 +861,7 @@ mod success {
.unwrap();

let asset_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -942,7 +942,7 @@ mod success {
.unwrap();

let token_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -1021,7 +1021,7 @@ mod success {
.unwrap();

let token_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value was received by the bridge contract
Expand Down Expand Up @@ -1133,7 +1133,7 @@ mod success {
.unwrap();

let token_balance =
contract_balance(&provider, bridge.contract_id(), AssetId::default()).await;
contract_balance(provider, bridge.contract_id(), AssetId::default()).await;
let balance = wallet_balance(&wallet, &get_asset_id(bridge.contract_id())).await;

// Verify the message value were received by the bridge contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ pub async fn build_contract_message_tx(
let number_of_contracts = contracts.len();
let mut tx_inputs: Vec<Input> = Vec::with_capacity(1 + number_of_contracts + gas_coins.len());
let mut tx_outputs: Vec<Output> = Vec::new();
let provider = wallet.provider().expect("Need to attach a provider to the wallet");
let provider = wallet
.provider()
.expect("Need to attach a provider to the wallet");


// Start building tx list of inputs
tx_inputs.push(message);
for contract in contracts {
Expand All @@ -54,6 +55,18 @@ pub async fn build_contract_message_tx(
tx_inputs.append(&mut gas_coins.to_vec());
}

// When funding the transaction with gas_coins, we need return the change of the UTXO
// back to the wallet
for gas_coin in gas_coins {
if let Input::ResourceSigned { resource } = gas_coin {
tx_outputs.push(Output::Change {
to: wallet.address().into(),
amount: 0,
asset_id: resource.asset_id(),
});
}
}

// Append provided outputs
tx_outputs.append(&mut optional_outputs.to_vec());

Expand Down
28 changes: 10 additions & 18 deletions packages/fungible-token/bridge-fungible-token/tests/utils/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use fuels::{
},
prelude::{
abigen, launch_provider_and_get_wallet, setup_custom_assets_coins, setup_test_provider,
Address, AssetConfig, AssetId, Bech32ContractId, Contract, ContractId,
LoadConfiguration, Provider, TxPolicies,
Address, AssetConfig, AssetId, Bech32ContractId, Contract, ContractId, LoadConfiguration,
Provider, TxPolicies,
},
test_helpers::{setup_single_message, DEFAULT_COIN_AMOUNT},
types::{input::Input, message::Message, Bits256},
Expand Down Expand Up @@ -172,10 +172,7 @@ pub(crate) async fn setup_environment(
deposit_contract: Option<ContractId>,
sender: Option<&str>,
configurables: Option<BridgeFungibleTokenContractConfigurables>,
) -> (
BridgeFungibleTokenContract<WalletUnlocked>,
UTXOInputs,
) {
) -> (BridgeFungibleTokenContract<WalletUnlocked>, UTXOInputs) {
// Generate coins for wallet
let asset_configs: Vec<AssetConfig> = coins
.iter()
Expand Down Expand Up @@ -210,14 +207,9 @@ pub(crate) async fn setup_environment(
}

// Create a provider with the coins and messages
let provider = setup_test_provider(
all_coins.clone(),
all_messages.clone(),
None,
None
)
.await
.unwrap();
let provider = setup_test_provider(all_coins.clone(), all_messages.clone(), None, None)
.await
.unwrap();

wallet.set_provider(provider);

Expand Down Expand Up @@ -279,7 +271,7 @@ pub(crate) async fn setup_environment(
contract: contract_inputs,
coin: coin_inputs,
message: message_inputs,
}
},
)
}

Expand All @@ -294,14 +286,14 @@ pub(crate) async fn relay_message_to_contract(
let gas_price = network_info.min_gas_price;
let tx_policies = TxPolicies::new(Some(gas_price), None, Some(0), None, Some(30_000));

let fetched_gas_coins: Vec<Input> = provider.get_coins(wallet.address(), Default::default())
let fetched_gas_coins: Vec<Input> = provider
.get_coins(wallet.address(), Default::default())
.await
.unwrap()
.iter()
.map(|el| { Input::resource_signed(fuels::types::coin_type::CoinType::Coin(el.clone())) })
.map(|el| Input::resource_signed(fuels::types::coin_type::CoinType::Coin(el.clone())))
.collect();


let tx = builder::build_contract_message_tx(
message,
contracts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ fn main() {

//output to console and build files
let script_hash = fuel_contract_message_predicate::script_hash();
let predicate_root =
fuel_contract_message_predicate::predicate_root();
let predicate_root = fuel_contract_message_predicate::predicate_root();
println!("Script bytecode size is {} bytes.", script.len());
println!("Script hash: 0x{}", Bytes32::from(script_hash));
println!("Predicate bytecode size is {} bytes.", predicate.len());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: packages/message-predicates/contract-message-predicate/src/lib.rs
assertion_line: 52
expression: serialized
---
1a405000910000206144000b6148000542411480504cc04c72580020295134165b501012615c000772680002595d7001616171015b61a0106165711a5b6400125b5c100b240400002400000009e68fb304ff158f1ae4a1f7675d19fc83d1843b9263f79a1c2350dbf9ea41dc
1a40500091000020614400096148000342411480504cc04c72580020295134165b501012615c000572680002595d7001616172005b61a010616572455b6400125b5c100b2404000024000000a77be53b9781aa004910c2a06a35b03b6b6909c64937c42a49d1e8185085c86f
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: packages/message-predicates/contract-message-predicate/src/lib.rs
assertion_line: 60
expression: serialized
---
1a40500091000050504500205049102461540117614c011d5050c02c60453020604940042d45540a24000000b93e6a3d
1a40500091000050504500205049102461540242614c02485050c02c60453020604940042d45540a24000000b93e6a3d
Loading

0 comments on commit 97a7b26

Please sign in to comment.