Skip to content

Commit 026deca

Browse files
Junha Yangmergify[bot]
authored andcommitted
Add a new integration test for events
1 parent 6a96c49 commit 026deca

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ hex = "0.4.2"
2020
ckey = {package = "codechain-key", path = "../key" }
2121
ccrypto = { package = "codechain-crypto", git = "https://github.com/CodeChain-io/rust-codechain-crypto.git", version = "0.3", tag = "v0.3.0" }
2222
rand = "0.7"
23+
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.5", tag = "v0.5.1" }
2324

2425
[features]
2526
integration-test = []

integration-test/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ pub async fn get_latest_block(port: u16) -> u64 {
151151
value["data"]["block"]["header"]["number"].as_u64().unwrap()
152152
}
153153

154+
pub async fn get_event(port: u16, tx_hash: primitives::H256) -> Vec<Vec<u8>> {
155+
let query = "query Test($txHash: String!) {
156+
event(txHash: $txHash)
157+
}";
158+
let mut variables = Value::Object(Default::default());
159+
variables["txHash"] = Value::String(hex::encode(tx_hash.as_ref()));
160+
161+
let query_result = request_query(port, "engine", query, &variables.to_string()).await;
162+
let value: Value = serde_json::from_str(&query_result).unwrap();
163+
let list = value["data"]["event"].as_array().unwrap();
164+
list.iter().map(|event| event.as_array().unwrap().iter().map(|x| x.as_i64().unwrap() as u8).collect()).collect()
165+
}
166+
154167
/// This is a copy from `foundry-timestamp`.
155168
#[derive(serde::Serialize, serde::Deserialize, Debug)]
156169
pub struct SignedTransaction {

integration-test/tests/integration_test.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,28 @@ async fn sequence_management2() {
152152
assert_eq!(value["data"]["account"]["seq"], tx_num_per_step * (i + 1));
153153
}
154154
}
155+
156+
#[actix_rt::test]
157+
async fn events() {
158+
let _node = run_node_override(simple_solo_node());
159+
delay_for(Duration::from_secs(3)).await;
160+
161+
let user: Ed25519KeyPair = Random.generate().unwrap();
162+
163+
let tx1 = create_tx_hello(GRAPHQL_PORT, user.public(), user.private(), 0).await;
164+
send_tx(GRAPHQL_PORT, tx1.tx_type(), tx1.body()).await.unwrap();
165+
166+
// invalid
167+
let tx2 = create_tx_hello(GRAPHQL_PORT, user.public(), user.private(), 100).await;
168+
send_tx(GRAPHQL_PORT, tx2.tx_type(), tx2.body()).await.unwrap();
169+
170+
delay_for(Duration::from_secs(4)).await;
171+
172+
let result = get_event(GRAPHQL_PORT, *tx1.hash()).await;
173+
174+
assert_eq!(1, result.len());
175+
assert_eq!(*tx1.body(), result[0]);
176+
177+
let result = get_event(GRAPHQL_PORT, *tx2.hash()).await;
178+
assert!(result.is_empty());
179+
}

timestamp/src/account/services.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ impl TxOwner for ServiceHandler {
8080
ExecuteError::NotAllowedHello => Err(()),
8181
}
8282
} else {
83-
Ok(Default::default())
83+
// For test/debug purpose, it returns an event which is just same as the content of transaction
84+
Ok(TransactionOutcome {
85+
events: vec![coordinator::types::Event {
86+
key: "".to_owned(),
87+
value: transaction.body().clone(),
88+
}],
89+
})
8490
}
8591
}
8692

0 commit comments

Comments
 (0)