-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathhyllar_test.rs
142 lines (112 loc) · 4.34 KB
/
hyllar_test.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
#![allow(clippy::unwrap_used, clippy::expect_used)]
use fixtures::ctx::E2ECtx;
use tracing::info;
mod fixtures;
use anyhow::Result;
mod e2e_hyllar {
use client_sdk::{
contract_states,
helpers::risc0::Risc0Prover,
transaction_builder::{ProvableBlobTx, TxExecutorBuilder},
};
use hydentity::{
client::{register_identity, verify_identity},
Hydentity,
};
use hyle_contract_sdk::{erc20::ERC20, guest, ContractInput, ContractName, HyleOutput};
use hyle_contracts::{HYDENTITY_ELF, HYLLAR_ELF};
use hyllar::{client::transfer, Hyllar, FAUCET_ID};
use super::*;
contract_states!(
struct States {
hydentity: Hydentity,
hyllar: Hyllar,
}
);
async fn scenario_hyllar(ctx: E2ECtx) -> Result<E2ECtx> {
info!("➡️ Setting up the executor with the initial state");
let hydentity: hydentity::Hydentity = ctx
.indexer_client()
.fetch_current_state(&"hydentity".into())
.await?;
let hyllar: Hyllar = ctx
.indexer_client()
.fetch_current_state(&"hyllar".into())
.await?;
let mut executor = TxExecutorBuilder::new(States { hydentity, hyllar })
// Replace prover binaries for non-reproducible mode.
.with_prover("hydentity".into(), Risc0Prover::new(HYDENTITY_ELF))
.with_prover("hyllar".into(), Risc0Prover::new(HYLLAR_ELF))
.build();
info!("➡️ Sending blob to register bob identity");
let mut tx = ProvableBlobTx::new("bob.hydentity".into());
register_identity(&mut tx, "hydentity".into(), "password".to_string())?;
ctx.send_provable_blob_tx(&tx).await?;
let tx = executor.process(tx)?;
let proof = tx.iter_prove().next().unwrap().await?;
info!("➡️ Sending proof for register");
ctx.send_proof_single(proof).await?;
info!("➡️ Waiting for height 2");
ctx.wait_height(2).await?;
info!("Hydentity: {:?}", executor.hydentity);
info!("➡️ Sending blob to transfer 25 tokens from faucet to bob");
let mut tx = ProvableBlobTx::new(FAUCET_ID.into());
verify_identity(
&mut tx,
"hydentity".into(),
&executor.hydentity,
"password".to_string(),
)?;
transfer(&mut tx, "hyllar".into(), "bob.hydentity".to_string(), 25)?;
ctx.send_provable_blob_tx(&tx).await?;
let tx = executor.process(tx)?;
let mut proofs = tx.iter_prove();
let hydentity_proof = proofs.next().unwrap().await?;
let hyllar_proof = proofs.next().unwrap().await?;
info!("➡️ Sending proof for hydentity");
ctx.send_proof_single(hydentity_proof).await?;
info!("➡️ Sending proof for hyllar");
ctx.send_proof_single(hyllar_proof).await?;
info!("➡️ Waiting for height 5");
ctx.wait_height(5).await?;
let state: Hyllar = ctx
.indexer_client()
.fetch_current_state(&"hyllar".into())
.await?;
assert_eq!(
state
.balance_of("bob.hydentity")
.expect("bob identity not found"),
25
);
Ok(ctx)
}
#[ignore = "need new_single_with_indexer"]
#[test_log::test(tokio::test)]
async fn hyllar_single_node() -> Result<()> {
let ctx = E2ECtx::new_single(500).await?;
scenario_hyllar(ctx).await?;
Ok(())
}
#[test_log::test(tokio::test)]
async fn hyllar_multi_nodes() -> Result<()> {
let ctx = E2ECtx::new_multi_with_indexer(2, 500).await?;
let node = ctx.client().get_node_info().await?;
let staking = ctx.client().get_consensus_staking_state().await?;
let initial_balance = staking
.fees
.balances
.get(node.pubkey.as_ref().unwrap())
.expect("balance");
let ctx = scenario_hyllar(ctx).await?;
let staking = ctx.client().get_consensus_staking_state().await?;
let balance = staking
.fees
.balances
.get(node.pubkey.as_ref().unwrap())
.expect("balance");
assert!(balance.cumul_size.0 > initial_balance.cumul_size.0);
assert!(balance.balance < initial_balance.balance);
Ok(())
}
}