-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_orchard_zsa.rs
147 lines (122 loc) · 4.67 KB
/
test_orchard_zsa.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
144
145
146
147
//! `test` - happy e2e flow that issues, transfers and burns an asset
use abscissa_core::{Command, Runnable};
use orchard::keys::Scope::External;
use crate::commands::test_balances::{check_balances, print_balances, TestBalances};
use crate::components::rpc_client::reqwest::ReqwestRpcClient;
use crate::components::transactions::sync_from_height;
use crate::components::transactions::{
create_burn_transaction, create_issue_transaction, create_transfer_transaction, mine,
};
use crate::components::user::User;
use crate::prelude::*;
/// Run the E2E test
#[derive(clap::Parser, Command, Debug)]
pub struct TestOrchardZSACmd {}
impl Runnable for TestOrchardZSACmd {
/// Run the `test` subcommand.
fn run(&self) {
let config = APP.config();
let mut rpc_client = ReqwestRpcClient::new(config.network.node_url());
let mut wallet = User::random(&config.wallet.miner_seed_phrase);
wallet.reset();
let issuer = wallet.address_for_account(0, External);
let alice = wallet.address_for_account(1, External);
let asset_description = b"WETH".to_vec();
prepare_test(
config.chain.v6_activation_height,
&mut wallet,
&mut rpc_client,
);
// --------------------- Issue asset ---------------------
let issue_tx =
create_issue_transaction(issuer, 1000, asset_description.clone(), &mut wallet);
let asset = issue_tx
.issue_bundle()
.unwrap()
.actions()
.head
.notes()
.first()
.unwrap()
.asset();
let balances = TestBalances::get_asset(asset, &mut wallet);
print_balances("=== Initial balances ===", asset, balances);
let current_height = wallet.last_block_height();
mine(
&mut wallet,
&mut rpc_client,
Vec::from([issue_tx]),
current_height.is_none(),
);
let balances = TestBalances::get_asset(asset, &mut wallet);
print_balances("=== Balances after issue ===", asset, balances);
// --------------------- ZSA transfer ---------------------
let amount_to_transfer_1 = 3;
let transfer_tx_1 =
create_transfer_transaction(issuer, alice, amount_to_transfer_1, asset, &mut wallet);
mine(
&mut wallet,
&mut rpc_client,
Vec::from([transfer_tx_1]),
false,
);
// transfer from issuer(account0) to alice(account1)
let expected_delta =
TestBalances::new(-(amount_to_transfer_1 as i64), amount_to_transfer_1 as i64);
check_balances(
"=== Balances after transfer ===",
asset,
balances,
expected_delta,
&mut wallet,
);
// --------------------- Burn asset ---------------------
let balances = TestBalances::get_asset(asset, &mut wallet);
let amount_to_burn_issuer = 7;
let amount_to_burn_alice = amount_to_transfer_1 - 1;
let burn_tx_issuer =
create_burn_transaction(issuer, amount_to_burn_issuer, asset, &mut wallet);
let burn_tx_alice =
create_burn_transaction(alice, amount_to_burn_alice, asset, &mut wallet);
mine(
&mut wallet,
&mut rpc_client,
Vec::from([burn_tx_issuer, burn_tx_alice]),
false,
);
// burn from issuer(account0) and alice(account1)
let expected_delta = TestBalances::new(
-(amount_to_burn_issuer as i64),
-(amount_to_burn_alice as i64),
);
check_balances(
"=== Balances after burning ===",
asset,
balances,
expected_delta,
&mut wallet,
);
// --------------------- Finalization ---------------------
// TODO - uncomment when finalization is implemented
// let finalization_tx = create_finalization_transaction(asset_description.clone(), &mut user);
// mine(
// &mut user,
// &mut rpc_client,
// Vec::from([finalization_tx]),
// false,
// );
//
// let invalid_issue_tx = create_issue_transaction(issuer, 2000, asset_description, &mut user);
// mine(
// &mut user,
// &mut rpc_client,
// Vec::from([invalid_issue_tx]),
// false,
// ); // TODO expect failure
//
// panic!("Invalid issue transaction was accepted");
}
}
fn prepare_test(target_height: u32, wallet: &mut User, rpc_client: &mut ReqwestRpcClient) {
sync_from_height(target_height, wallet, rpc_client);
}