Skip to main content

o2_tools/
src20_mock.rs

1use fuels::{
2    accounts::{
3        signers::private_key::PrivateKeySigner,
4        wallet::{
5            Unlocked,
6            Wallet,
7        },
8    },
9    macros::abigen,
10    programs::contract::Contract,
11    tx::StorageSlot,
12    types::{
13        ContractId,
14        Salt,
15        transaction::TxPolicies,
16    },
17};
18
19abigen!(Contract(
20    name = "Src20Mock",
21    abi = "artifacts/test_artifacts/src20-mock-abi.json"
22));
23
24pub const SRC20_MOCK_BYTECODE: &[u8] =
25    include_bytes!("../artifacts/test_artifacts/src20-mock.bin");
26
27pub const SRC20_MOCK_STORAGE_SLOTS: &str =
28    include_str!("../artifacts/test_artifacts/src20-mock-storage_slots.json");
29
30pub async fn setup_src20_mock(
31    wallet: &Wallet<Unlocked<PrivateKeySigner>>,
32) -> (Src20Mock<Wallet<Unlocked<PrivateKeySigner>>>, ContractId) {
33    let storage_slots: Vec<StorageSlot> = serde_json::from_str(SRC20_MOCK_STORAGE_SLOTS)
34        .expect("failed to parse storage slots");
35
36    let id =
37        Contract::regular(SRC20_MOCK_BYTECODE.to_vec(), Salt::default(), storage_slots)
38            .deploy(wallet, TxPolicies::default())
39            .await
40            .unwrap()
41            .contract_id;
42
43    let instance = Src20Mock::new(id, wallet.clone());
44
45    (instance, id)
46}