/
harness.rs
68 lines (56 loc) · 1.61 KB
/
harness.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use fuels::{prelude::*, types::{ContractId, Identity}};
// Load abi from json
abigen!(Contract(
name = "MyContract",
abi = "out/debug/test-token-transfer-abi.json"
));
async fn get_contract_instance() -> (MyContract<WalletUnlocked>, ContractId, Vec<WalletUnlocked>) {
// Launch a local network and deploy the contract
let mut wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(
Some(5), /* Single wallet */
Some(1), /* Single coin (UTXO) */
Some(1_000_000_000), /* Amount per coin */
),
None,
None,
)
.await;
let wallet = wallets.pop().unwrap();
let id = Contract::load_from(
"./out/debug/test-token-transfer.bin",
LoadConfiguration::default(),
)
.unwrap()
.deploy(&wallet, TxParameters::default())
.await
.unwrap();
let instance = MyContract::new(id.clone(), wallet);
(instance, id.into(), wallets)
}
#[tokio::test]
async fn test_transfer() {
let (inst, inst_id, wallets) = get_contract_instance().await;
// deposit
let call_params = CallParameters::default()
.set_amount(100)
.set_asset_id(BASE_ASSET_ID);
inst
.methods()
.deposit()
.call_params(call_params)
.unwrap()
.call()
.await
.unwrap();
let to_addr = Address::from(wallets[1].address());
let to = Identity::Address(to_addr);
let res = inst
.methods()
.transfer(10, to)
.append_variable_outputs(1)
.call()
.await;
dbg!(res);
// res.unwrap();
}