Skip to content

Commit e53f4da

Browse files
authored
Add a feature to generate testing transactions (#518)
* Add a feature to generat testing transactions that can be used for processor testing. This enables us to skip creating a pr whenever there is new transaction to test with. * lint
1 parent 51a3490 commit e53f4da

12 files changed

+2396
-0
lines changed

rust/Cargo.lock

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

rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"processor",
99
"sdk-processor",
1010
"server-framework",
11+
"testing-transactions",
1112
]
1213

1314
[workspace.package]
@@ -25,6 +26,7 @@ server-framework = { path = "server-framework" }
2526
aptos-moving-average = { path = "moving-average" }
2627
integration-tests = { path = "integration-tests" }
2728
sdk-processor = { path = "sdk-processor" }
29+
testing-transactions = { path = "testing-transactions" }
2830

2931
ahash = { version = "0.8.7", features = ["serde"] }
3032
anyhow = "1.0.86"

rust/integration-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ regex = { workspace = true }
2626
serde = { workspace = true }
2727
serde_json = { workspace = true }
2828
testcontainers = { workspace = true }
29+
testing-transactions = { workspace = true }
2930
tokio = { workspace = true }
3031
[dev-dependencies]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "testing-transactions"
3+
version = "0.1.0"
4+
5+
# Workspace inherited keys
6+
authors = { workspace = true }
7+
edition = { workspace = true }
8+
homepage = { workspace = true }
9+
license = { workspace = true }
10+
publish = { workspace = true }
11+
repository = { workspace = true }
12+
rust-version = { workspace = true }
13+
14+
[dependencies]
15+
aptos-protos ={ workspace = true }
16+
serde_json = { workspace = true }

rust/testing-transactions/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Aptos Foundation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// build.rs
5+
use std::{env, fs, path::Path};
6+
7+
fn main() {
8+
let out_dir = env::var("OUT_DIR").unwrap();
9+
println!("OUT_DIR: {:?}", out_dir);
10+
let dest_path = Path::new(&out_dir).join("generate_transactions.rs");
11+
let mut transactions_code = String::new();
12+
let json_dir = Path::new("json_transactions");
13+
for entry in fs::read_dir(json_dir).unwrap() {
14+
let entry = entry.unwrap();
15+
let path = entry.path();
16+
if path.extension().and_then(|s| s.to_str()) == Some("json") {
17+
let file_name = path.file_stem().unwrap().to_str().unwrap();
18+
let const_name = file_name.to_uppercase().replace('-', "_");
19+
20+
let json_code = format!(
21+
r#"
22+
pub const {const_name}: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/json_transactions/{file_name}.json"));
23+
"#,
24+
const_name = const_name,
25+
file_name = file_name,
26+
);
27+
transactions_code.push_str(&json_code);
28+
}
29+
}
30+
fs::write(dest_path, transactions_code).unwrap();
31+
}
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
{
2+
"timestamp": {
3+
"seconds": "1722246280",
4+
"nanos": 999230000
5+
},
6+
"version": "5524190992",
7+
"info": {
8+
"hash": "9u1tiBJTfUpcFsoKtJKfqpb4hWbz6Zq0+l/kmJrvmRQ=",
9+
"stateChangeHash": "dSvWbb9A1Njayi8522XP4CRnJEaIXcgPL9hwMuLC2Ls=",
10+
"eventRootHash": "iX1ELvz8fXL4p6APhREH/kP5KQq4Fw/T3Isrcc3W9+Y=",
11+
"gasUsed": "1001",
12+
"success": true,
13+
"vmStatus": "Executed successfully",
14+
"accumulatorRootHash": "zxr63s4RL8yAwM+AZduTy0j2diWNi328bJKtCD+fekU=",
15+
"changes": [
16+
{
17+
"type": "TYPE_WRITE_RESOURCE",
18+
"writeResource": {
19+
"address": "0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb",
20+
"stateKeyHash": "NO4exGs6RLXsCA6pGBWJ3i5FxUR9urylYXvjxzGBVE4=",
21+
"type": {
22+
"address": "0x1",
23+
"module": "coin",
24+
"name": "CoinStore",
25+
"genericTypeParams": [
26+
{
27+
"type": "MOVE_TYPES_STRUCT",
28+
"struct": {
29+
"address": "0x1",
30+
"module": "aptos_coin",
31+
"name": "AptosCoin"
32+
}
33+
}
34+
]
35+
},
36+
"typeStr": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
37+
"data": "{\"coin\":{\"value\":\"225379021750\"},\"deposit_events\":{\"counter\":\"1345637\",\"guid\":{\"id\":{\"addr\":\"0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb\",\"creation_num\":\"2\"}}},\"frozen\":false,\"withdraw_events\":{\"counter\":\"1345624\",\"guid\":{\"id\":{\"addr\":\"0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb\",\"creation_num\":\"3\"}}}}"
38+
}
39+
},
40+
{
41+
"type": "TYPE_WRITE_RESOURCE",
42+
"writeResource": {
43+
"address": "0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb",
44+
"stateKeyHash": "u34zRmqkZYLKVzYCOBOMbWPtN8szyG02m+Of/dmxFUw=",
45+
"type": {
46+
"address": "0x1",
47+
"module": "account",
48+
"name": "Account"
49+
},
50+
"typeStr": "0x1::account::Account",
51+
"data": "{\"authentication_key\":\"0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb\",\"coin_register_events\":{\"counter\":\"1\",\"guid\":{\"id\":{\"addr\":\"0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb\",\"creation_num\":\"0\"}}},\"guid_creation_num\":\"4\",\"key_rotation_events\":{\"counter\":\"0\",\"guid\":{\"id\":{\"addr\":\"0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb\",\"creation_num\":\"1\"}}},\"rotation_capability_offer\":{\"for\":{\"vec\":[]}},\"sequence_number\":\"1345635\",\"signer_capability_offer\":{\"for\":{\"vec\":[]}}}"
52+
}
53+
},
54+
{
55+
"type": "TYPE_WRITE_RESOURCE",
56+
"writeResource": {
57+
"address": "0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2",
58+
"stateKeyHash": "iSj4XNRWy0NEu971y15qfgX60oXWnPW/2MUkQGCUBrc=",
59+
"type": {
60+
"address": "0x1",
61+
"module": "coin",
62+
"name": "CoinStore",
63+
"genericTypeParams": [
64+
{
65+
"type": "MOVE_TYPES_STRUCT",
66+
"struct": {
67+
"address": "0x1",
68+
"module": "aptos_coin",
69+
"name": "AptosCoin"
70+
}
71+
}
72+
]
73+
},
74+
"typeStr": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
75+
"data": "{\"coin\":{\"value\":\"100000000\"},\"deposit_events\":{\"counter\":\"1\",\"guid\":{\"id\":{\"addr\":\"0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2\",\"creation_num\":\"2\"}}},\"frozen\":false,\"withdraw_events\":{\"counter\":\"0\",\"guid\":{\"id\":{\"addr\":\"0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2\",\"creation_num\":\"3\"}}}}"
76+
}
77+
},
78+
{
79+
"type": "TYPE_WRITE_RESOURCE",
80+
"writeResource": {
81+
"address": "0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2",
82+
"stateKeyHash": "WItcVnHUvRZJFz30CYBH/6JKkFJO2SsICXYp1nads8U=",
83+
"type": {
84+
"address": "0x1",
85+
"module": "account",
86+
"name": "Account"
87+
},
88+
"typeStr": "0x1::account::Account",
89+
"data": "{\"authentication_key\":\"0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2\",\"coin_register_events\":{\"counter\":\"1\",\"guid\":{\"id\":{\"addr\":\"0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2\",\"creation_num\":\"0\"}}},\"guid_creation_num\":\"4\",\"key_rotation_events\":{\"counter\":\"0\",\"guid\":{\"id\":{\"addr\":\"0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2\",\"creation_num\":\"1\"}}},\"rotation_capability_offer\":{\"for\":{\"vec\":[]}},\"sequence_number\":\"0\",\"signer_capability_offer\":{\"for\":{\"vec\":[]}}}"
90+
}
91+
},
92+
{
93+
"type": "TYPE_WRITE_TABLE_ITEM",
94+
"writeTableItem": {
95+
"stateKeyHash": "bkso1A+YoQamUWNTCSTA3LQME0nTqpFdEItNbPwd2xk=",
96+
"handle": "0x1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca",
97+
"key": "0x0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935",
98+
"data": {
99+
"key": "\"0x619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935\"",
100+
"keyType": "address",
101+
"value": "\"29159041932810165790\"",
102+
"valueType": "u128"
103+
}
104+
}
105+
}
106+
]
107+
},
108+
"epoch": "16653",
109+
"blockHeight": "322562789",
110+
"type": "TRANSACTION_TYPE_USER",
111+
"sizeInfo": {
112+
"transactionBytes": 475,
113+
"eventSizeInfo": [
114+
{
115+
"typeTagBytes": 52,
116+
"totalBytes": 108
117+
},
118+
{
119+
"typeTagBytes": 60,
120+
"totalBytes": 161
121+
},
122+
{
123+
"typeTagBytes": 53,
124+
"totalBytes": 109
125+
},
126+
{
127+
"typeTagBytes": 52,
128+
"totalBytes": 108
129+
},
130+
{
131+
"typeTagBytes": 63,
132+
"totalBytes": 103
133+
}
134+
],
135+
"writeOpSizeInfo": [
136+
{
137+
"keyBytes": 138,
138+
"valueBytes": 105
139+
},
140+
{
141+
"keyBytes": 84,
142+
"valueBytes": 147
143+
},
144+
{
145+
"keyBytes": 138,
146+
"valueBytes": 105
147+
},
148+
{
149+
"keyBytes": 84,
150+
"valueBytes": 147
151+
},
152+
{
153+
"keyBytes": 66,
154+
"valueBytes": 16
155+
}
156+
]
157+
},
158+
"user": {
159+
"request": {
160+
"sender": "0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb",
161+
"sequenceNumber": "1345634",
162+
"maxGasAmount": "500000",
163+
"gasUnitPrice": "100",
164+
"expirationTimestampSecs": {
165+
"seconds": "1722246295"
166+
},
167+
"payload": {
168+
"type": "TYPE_SCRIPT_PAYLOAD",
169+
"scriptPayload": {
170+
"code": {
171+
"bytecode": "oRzrCwUAAAAIAQAIAggEAwwVBCECBSMQBzNQCIMBIAajARQAAAABAAIAAwEFCAADBAMBAAIGAQUBAAEHAAIAAAgAAgABBAMGDAUDAQUAAQYMAQgAAQMNYXB0b3NfYWNjb3VudAphcHRvc19jb2luBGNvaW4Gc2lnbmVyCmFkZHJlc3Nfb2YJQXB0b3NDb2luB2JhbGFuY2UEbWludAh0cmFuc2ZlcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAwighgEAAAAAAAMI//////////8AAAEXCgARAAwDCgM4AAcBCgIXBwAXIwQSCgALAwoCBwAWEQILAAsBCwIRAwI=",
172+
"abi": {
173+
"name": "main",
174+
"visibility": "VISIBILITY_PUBLIC",
175+
"isEntry": true,
176+
"params": [
177+
{
178+
"type": "MOVE_TYPES_REFERENCE",
179+
"reference": {
180+
"to": {
181+
"type": "MOVE_TYPES_SIGNER"
182+
}
183+
}
184+
},
185+
{
186+
"type": "MOVE_TYPES_ADDRESS"
187+
},
188+
{
189+
"type": "MOVE_TYPES_U64"
190+
}
191+
]
192+
}
193+
},
194+
"arguments": [
195+
"\"0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2\"",
196+
"\"100000000\""
197+
]
198+
}
199+
},
200+
"signature": {
201+
"type": "TYPE_ED25519",
202+
"ed25519": {
203+
"publicKey": "UFdI6CaGx2yWzNCGgupSjfWTm9vbCnlDGdJkKxaVv5c=",
204+
"signature": "CsqIVmJ7mLaoGk4qwyQ5DqfUpdX0KFdKVUy6uLFTcblcGIhtX93j2JuMcLFI42be/3aNTCw25aJKT16l3HXeBg=="
205+
}
206+
}
207+
},
208+
"events": [
209+
{
210+
"key": {
211+
"creationNumber": "2",
212+
"accountAddress": "0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb"
213+
},
214+
"sequenceNumber": "1345636",
215+
"type": {
216+
"type": "MOVE_TYPES_STRUCT",
217+
"struct": {
218+
"address": "0x1",
219+
"module": "coin",
220+
"name": "DepositEvent"
221+
}
222+
},
223+
"typeStr": "0x1::coin::DepositEvent",
224+
"data": "{\"amount\":\"100100000\"}"
225+
},
226+
{
227+
"key": {
228+
"accountAddress": "0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2"
229+
},
230+
"type": {
231+
"type": "MOVE_TYPES_STRUCT",
232+
"struct": {
233+
"address": "0x1",
234+
"module": "account",
235+
"name": "CoinRegisterEvent"
236+
}
237+
},
238+
"typeStr": "0x1::account::CoinRegisterEvent",
239+
"data": "{\"type_info\":{\"account_address\":\"0x1\",\"module_name\":\"0x6170746f735f636f696e\",\"struct_name\":\"0x4170746f73436f696e\"}}"
240+
},
241+
{
242+
"key": {
243+
"creationNumber": "3",
244+
"accountAddress": "0x832fd5e456b7f43c4ef27978766ee5242a8a393d10ef5bf662d40f774a6f2deb"
245+
},
246+
"sequenceNumber": "1345623",
247+
"type": {
248+
"type": "MOVE_TYPES_STRUCT",
249+
"struct": {
250+
"address": "0x1",
251+
"module": "coin",
252+
"name": "WithdrawEvent"
253+
}
254+
},
255+
"typeStr": "0x1::coin::WithdrawEvent",
256+
"data": "{\"amount\":\"100000000\"}"
257+
},
258+
{
259+
"key": {
260+
"creationNumber": "2",
261+
"accountAddress": "0xeea01e0c163fe390e30afd0e6ff88a3535a2d78b4cbbcc8f9bf3848b5a8fbcf2"
262+
},
263+
"type": {
264+
"type": "MOVE_TYPES_STRUCT",
265+
"struct": {
266+
"address": "0x1",
267+
"module": "coin",
268+
"name": "DepositEvent"
269+
}
270+
},
271+
"typeStr": "0x1::coin::DepositEvent",
272+
"data": "{\"amount\":\"100000000\"}"
273+
},
274+
{
275+
"key": {
276+
"accountAddress": "0x0"
277+
},
278+
"type": {
279+
"type": "MOVE_TYPES_STRUCT",
280+
"struct": {
281+
"address": "0x1",
282+
"module": "transaction_fee",
283+
"name": "FeeStatement"
284+
}
285+
},
286+
"typeStr": "0x1::transaction_fee::FeeStatement",
287+
"data": "{\"execution_gas_units\":\"6\",\"io_gas_units\":\"7\",\"storage_fee_octas\":\"98800\",\"storage_fee_refund_octas\":\"0\",\"total_charge_gas_units\":\"1001\"}"
288+
}
289+
]
290+
}
291+
}

0 commit comments

Comments
 (0)