-
Notifications
You must be signed in to change notification settings - Fork 0
/
harness.rs
143 lines (111 loc) · 4.09 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
mod tests {
use std::{mem::size_of, str::FromStr};
use fuel_core_types::fuel_vm::SecretKey;
use fuel_tx::ContractId;
use fuels::{
accounts::wallet::WalletUnlocked,
prelude::{abigen, setup_test_provider, AssetId, Contract},
test_helpers::{setup_custom_assets_coins, AssetConfig},
programs::contract::LoadConfiguration,
};
abigen!(Contract(
name = "MyContract",
abi = "out/debug/my-fuel-project-abi.json",
));
const CONTRACT_BINARY: &str = "out/debug/my-fuel-project.bin";
pub const DEFAULT_COIN_AMOUNT: u64 = 1_000_000_000;
fn create_wallet() -> WalletUnlocked {
const SIZE_SECRET_KEY: usize = size_of::<SecretKey>();
const PADDING_BYTES: usize = SIZE_SECRET_KEY - size_of::<u64>();
let mut secret_key: [u8; SIZE_SECRET_KEY] = [0; SIZE_SECRET_KEY];
secret_key[PADDING_BYTES..].copy_from_slice(&(8320147306839812359u64).to_be_bytes());
let wallet = WalletUnlocked::new_from_private_key(
SecretKey::try_from(secret_key.as_slice()).unwrap(),
None,
);
wallet
}
#[tokio::test]
async fn test_without_configurables() {
let mut wallet = create_wallet();
let coin = (DEFAULT_COIN_AMOUNT, AssetId::default());
// Generate coins for wallet
let asset_configs = vec![AssetConfig {
id: coin.1,
num_coins: 1,
coin_amount: coin.0,
}];
let all_coins = setup_custom_assets_coins(wallet.address(), &asset_configs[..]);
let provider = setup_test_provider(
all_coins.clone(),
vec![],
None,
None,
)
.await
.expect("Could not instantiate provider");
wallet.set_provider(provider.clone());
let configurables = MyContractConfigurables::default()
.with_INITIAL_OWNER(State::Initialized(wallet.address().into()))
.unwrap()
.with_INITIAL_TARGET(
ContractId::from_str(
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
).unwrap()
)
.unwrap();
let load_configuration = LoadConfiguration::default().with_configurables(configurables);
let test_contract_id =
Contract::load_from(CONTRACT_BINARY, load_configuration)
.unwrap()
.deploy(&wallet.clone(), Default::default())
.await
.unwrap();
let contract = MyContract::new(test_contract_id.clone(), wallet.clone());
let value = 255u64;
let result = contract
.methods()
._proxy_pure_fn()
.call()
.await
.unwrap();
assert_eq!(value, result.value);
}
#[tokio::test]
async fn test_with_configurables() {
let mut wallet = create_wallet();
let coin = (DEFAULT_COIN_AMOUNT, AssetId::default());
// Generate coins for wallet
let asset_configs = vec![AssetConfig {
id: coin.1,
num_coins: 1,
coin_amount: coin.0,
}];
let all_coins = setup_custom_assets_coins(wallet.address(), &asset_configs[..]);
let provider = setup_test_provider(
all_coins.clone(),
vec![],
None,
None,
)
.await
.expect("Could not instantiate provider");
wallet.set_provider(provider.clone());
let load_configuration = LoadConfiguration::default();
let test_contract_id =
Contract::load_from(CONTRACT_BINARY, load_configuration)
.unwrap()
.deploy(&wallet.clone(), Default::default())
.await
.unwrap();
let contract = MyContract::new(test_contract_id.clone(), wallet.clone());
let value = 255u64;
let result = contract
.methods()
._proxy_pure_fn()
.call()
.await
.unwrap();
assert_eq!(value, result.value);
}
}