Skip to content

Commit

Permalink
Merge branch 'main' into deficake/mainnet-sway-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
DefiCake authored Sep 11, 2024
2 parents 2db8513 + 4cbf8dc commit 6f720da
Show file tree
Hide file tree
Showing 12 changed files with 793 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-zebras-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-bridge/test-utils': minor
---

integrate fork tokens in e2e test
5 changes: 5 additions & 0 deletions .changeset/plenty-rice-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-bridge/fungible-token': minor
---

Updated sway contracts compiler to forc v0.63.4
Binary file removed packages/base-asset/bin/base-asset-contract.bin
Binary file not shown.
1 change: 0 additions & 1 deletion packages/base-asset/bin/base-asset-contract.hex

This file was deleted.

67 changes: 4 additions & 63 deletions packages/base-asset/tests/harness.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use fuels::{
prelude::*,
types::{Bytes32, ContractId},
types::ContractId,
};
use sha2::{Digest, Sha256};
use std::{fs, str::FromStr};

// Matches the README addresses
const BASE_ASSET_CONTRACT_ID: &str =
"0xab724dea11ad246edc359338a6e3cfe6dabdf18740c3b2cf417cc4b1f9453512";
const BASE_ASSET_ID: &str = "0x157b59fb83fc65a53100dda502e6100fc6b1e28ceee3d038c5ef3084bfeae75e";
const BASE_ASSET_CONTRACT_BYTECODE_PATH: &str = "out/release/base-asset-contract.bin";
const BASE_ASSET_CONTRACT_HEX_PATH: &str = "bin/base-asset-contract.hex";
const BASE_ASSET_CONTRACT_BIN_PATH: &str = "bin/base-asset-contract.bin";

abigen!(Contract(
name = "BaseAssetContract",
Expand Down Expand Up @@ -49,59 +41,8 @@ async fn get_contract_instance() -> (BaseAssetContract<WalletUnlocked>, Contract
}

#[tokio::test]
async fn asset_id_matches_expected() {
async fn can_be_deployed() {
let (_instance, id) = get_contract_instance().await;

let base_asset_id = get_asset_id(Bytes32::zeroed(), id);

assert_eq!(base_asset_id, AssetId::from_str(BASE_ASSET_ID).unwrap());
}

#[tokio::test]
async fn contract_id_matches_expected() {
let (_instance, id) = get_contract_instance().await;

assert_eq!(id, ContractId::from_str(BASE_ASSET_CONTRACT_ID).unwrap());
}

#[tokio::test]
async fn expected_hex_matches_bin() {
// Get the bytecode and hex for the contract
let compiled_bytecode = base_asset_contract_bytecode();
let file_hex = base_asset_contract_hex();

// Convert to hex
let hex_bytecode = hex::encode(compiled_bytecode);

// Assert the hex is correct
assert_eq!(file_hex, hex_bytecode);
}

#[tokio::test]
async fn compiled_bin_matches_expected_bin() {
// Get the bytecode and hex for the contract
let compiled_bytecode = base_asset_contract_bytecode();
let file_bytecode = base_asset_contract_binaires();

// Assert the hex is correct
assert_eq!(file_bytecode, compiled_bytecode);
}

pub fn base_asset_contract_bytecode() -> Vec<u8> {
fs::read(BASE_ASSET_CONTRACT_BYTECODE_PATH).unwrap()
}

pub fn base_asset_contract_hex() -> String {
fs::read_to_string(BASE_ASSET_CONTRACT_HEX_PATH).unwrap()
}

pub fn base_asset_contract_binaires() -> Vec<u8> {
fs::read(BASE_ASSET_CONTRACT_BIN_PATH).unwrap()
}

pub fn get_asset_id(sub_id: Bytes32, contract: ContractId) -> AssetId {
let mut hasher = Sha256::new();
hasher.update(*contract);
hasher.update(*sub_id);
AssetId::new(*Bytes32::from(<[u8; 32]>::from(hasher.finalize())))
}
assert_ne!(id, ContractId::zeroed());
}
Loading

0 comments on commit 6f720da

Please sign in to comment.