Skip to content

Commit 577cdcd

Browse files
authored
Merge pull request #454 from AmbireTech/validator-stack-testcases
Validator stack - Running Workers tick & inserting events
2 parents 0af06f7 + c6e9d09 commit 577cdcd

File tree

196 files changed

+1172
-945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+1172
-945
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010

1111
[features]
1212

13-
test-util = []
13+
test-util = ["primitives/test-util"]
1414

1515
[dependencies]
1616
primitives = { path = "../primitives" }

adapter/src/ethereum.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,10 @@ mod test {
501501
use super::test_util::*;
502502
use super::*;
503503
use chrono::Utc;
504-
use primitives::{config::DEVELOPMENT_CONFIG, util::tests::prep_db::IDS};
504+
use primitives::{
505+
config::DEVELOPMENT_CONFIG,
506+
test_util::{CREATOR, IDS, LEADER},
507+
};
505508
use web3::{transports::Http, Web3};
506509
use wiremock::{
507510
matchers::{method, path},
@@ -636,7 +639,7 @@ mod test {
636639
async fn get_deposit_and_count_create2_when_min_tokens_received() {
637640
let web3 = Web3::new(Http::new(GANACHE_URL).expect("failed to init transport"));
638641

639-
let leader_account = GANACHE_ADDRESSES["leader"];
642+
let leader_account = *LEADER;
640643

641644
// deploy contracts
642645
let token = deploy_token_contract(&web3, 1_000)
@@ -652,7 +655,7 @@ mod test {
652655
.await
653656
.expect("Correct parameters are passed to the OUTPACE constructor.");
654657

655-
let spender = GANACHE_ADDRESSES["creator"];
658+
let spender = *CREATOR;
656659

657660
let channel = get_test_channel(token_address);
658661

@@ -693,7 +696,7 @@ mod test {
693696
{
694697
mock_set_balance(
695698
&token.2,
696-
*GANACHE_ADDRESSES["leader"].as_bytes(),
699+
*LEADER.as_bytes(),
697700
*spender.as_bytes(),
698701
&BigNum::from(10_000),
699702
)

adapter/src/ethereum/test_util.rs

+25-124
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use primitives::{
1212
adapter::KeystoreOptions,
1313
channel::{Channel, Nonce},
1414
config::TokenInfo,
15+
test_util::{ADVERTISER, CREATOR, FOLLOWER, GUARDIAN, GUARDIAN_2, LEADER, PUBLISHER},
1516
Address, BigNum, Config, ValidatorId,
1617
};
1718

@@ -48,129 +49,41 @@ pub static KEYSTORE_IDENTITY: Lazy<(Address, KeystoreOptions)> = Lazy::new(|| {
4849
(address, keystore_options("keystore.json", "adexvalidator"))
4950
});
5051

51-
pub static GANACHE_KEYSTORES: Lazy<HashMap<String, (Address, KeystoreOptions)>> = Lazy::new(|| {
52+
pub static KEYSTORES: Lazy<HashMap<Address, KeystoreOptions>> = Lazy::new(|| {
5253
vec![
5354
(
54-
"guardian".to_string(),
55-
(
56-
"0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39"
57-
.parse()
58-
.expect("Valid Address"),
59-
keystore_options(
60-
"0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39_keystore.json",
61-
"address0",
62-
),
63-
),
64-
),
65-
(
66-
"leader".to_string(),
67-
(
68-
"0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5"
69-
.parse()
70-
.expect("Valid Address"),
71-
keystore_options(
72-
"0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5_keystore.json",
73-
"address1",
74-
),
75-
),
76-
),
77-
(
78-
"follower".to_string(),
79-
(
80-
"0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02"
81-
.parse()
82-
.expect("Valid Address"),
83-
keystore_options(
84-
"0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02_keystore.json",
85-
"address2",
86-
),
87-
),
88-
),
89-
(
90-
"creator".to_string(),
91-
(
92-
"0x0E45891a570Af9e5A962F181C219468A6C9EB4e1"
93-
.parse()
94-
.expect("Valid Address"),
95-
keystore_options(
96-
"0x0E45891a570Af9e5A962F181C219468A6C9EB4e1_keystore.json",
97-
"address3",
98-
),
99-
),
100-
),
101-
(
102-
"advertiser".to_string(),
103-
(
104-
"0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d"
105-
.parse()
106-
.expect("Valid Address"),
107-
keystore_options(
108-
"0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d_keystore.json",
109-
"address4",
110-
),
111-
),
112-
),
113-
(
114-
"guardian2".to_string(),
115-
(
116-
"0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8"
117-
.parse()
118-
.expect("Valid Address"),
119-
keystore_options(
120-
"0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8_keystore.json",
121-
"address5",
122-
),
123-
),
55+
*LEADER,
56+
keystore_options(&format!("{}_keystore.json", *LEADER), "ganache0"),
12457
),
125-
]
126-
.into_iter()
127-
.collect()
128-
});
129-
130-
/// Addresses generated on local running `ganache` for testing purposes.
131-
/// see the `ganache-cli.sh` script in the repository
132-
pub static GANACHE_ADDRESSES: Lazy<HashMap<String, Address>> = Lazy::new(|| {
133-
vec![
13458
(
135-
"guardian".to_string(),
136-
"0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39"
137-
.parse()
138-
.expect("Valid Address"),
59+
*FOLLOWER,
60+
keystore_options(&format!("{}_keystore.json", *FOLLOWER), "ganache1"),
13961
),
14062
(
141-
"leader".to_string(),
142-
"0x5a04A8fB90242fB7E1db7d1F51e268A03b7f93A5"
143-
.parse()
144-
.expect("Valid Address"),
63+
*GUARDIAN,
64+
keystore_options(&format!("{}_keystore.json", *GUARDIAN), "ganache2"),
14565
),
14666
(
147-
"follower".to_string(),
148-
"0xe3896ebd3F32092AFC7D27e9ef7b67E26C49fB02"
149-
.parse()
150-
.expect("Valid Address"),
67+
*CREATOR,
68+
keystore_options(&format!("{}_keystore.json", *CREATOR), "ganache3"),
15169
),
15270
(
153-
"creator".to_string(),
154-
"0x0E45891a570Af9e5A962F181C219468A6C9EB4e1"
155-
.parse()
156-
.expect("Valid Address"),
71+
*ADVERTISER,
72+
keystore_options(&format!("{}_keystore.json", *ADVERTISER), "ganache4"),
15773
),
15874
(
159-
"advertiser".to_string(),
160-
"0x8c4B95383a46D30F056aCe085D8f453fCF4Ed66d"
161-
.parse()
162-
.expect("Valid Address"),
75+
*PUBLISHER,
76+
keystore_options(&format!("{}_keystore.json", *PUBLISHER), "ganache5"),
16377
),
16478
(
165-
"guardian2".to_string(),
166-
"0x1059B025E3F8b8f76A8120D6D6Fd9fBa172c80b8"
167-
.parse()
168-
.expect("Valid Address"),
79+
*GUARDIAN_2,
80+
keystore_options(&format!("{}_keystore.json", *GUARDIAN_2), "ganache6"),
16981
),
17082
]
17183
.into_iter()
17284
.collect()
17385
});
86+
17487
/// Local `ganache` is running at:
17588
pub const GANACHE_URL: &str = "http://localhost:8545";
17689

@@ -193,9 +106,9 @@ fn keystore_options(file_name: &str, password: &str) -> KeystoreOptions {
193106

194107
pub fn get_test_channel(token_address: Address) -> Channel {
195108
Channel {
196-
leader: ValidatorId::from(&GANACHE_ADDRESSES["leader"]),
197-
follower: ValidatorId::from(&GANACHE_ADDRESSES["follower"]),
198-
guardian: GANACHE_ADDRESSES["advertiser"],
109+
leader: ValidatorId::from(&LEADER),
110+
follower: ValidatorId::from(&FOLLOWER),
111+
guardian: *GUARDIAN,
199112
token: token_address,
200113
nonce: Nonce::from(12345_u32),
201114
}
@@ -251,7 +164,7 @@ pub async fn sweeper_sweep(
251164
channel: &Channel,
252165
depositor: [u8; 20],
253166
) -> web3::contract::Result<H256> {
254-
let from_leader_account = H160(*GANACHE_ADDRESSES["leader"].as_bytes());
167+
let from_leader_account = H160(*LEADER.as_bytes());
255168

256169
sweeper_contract
257170
.call(
@@ -281,11 +194,7 @@ pub async fn deploy_sweeper_contract(
281194
opt.gas_price = Some(1.into());
282195
opt.gas = Some(6_721_975.into());
283196
}))
284-
.execute(
285-
*SWEEPER_BYTECODE,
286-
(),
287-
H160(GANACHE_ADDRESSES["leader"].to_bytes()),
288-
)
197+
.execute(*SWEEPER_BYTECODE, (), H160(LEADER.to_bytes()))
289198
.await?;
290199

291200
let sweeper_address = Address::from(sweeper_contract.address().to_fixed_bytes());
@@ -304,18 +213,14 @@ pub async fn deploy_outpace_contract(
304213
opt.gas_price = Some(1.into());
305214
opt.gas = Some(6_721_975.into());
306215
}))
307-
.execute(
308-
*OUTPACE_BYTECODE,
309-
(),
310-
H160(GANACHE_ADDRESSES["leader"].to_bytes()),
311-
)
216+
.execute(*OUTPACE_BYTECODE, (), H160(LEADER.to_bytes()))
312217
.await?;
313218
let outpace_address = Address::from(outpace_contract.address().to_fixed_bytes());
314219

315220
Ok((outpace_address, outpace_contract))
316221
}
317222

318-
/// Deploys the Mock Token contract from `GANACHE_ADDRESS['leader']`
223+
/// Deploys the Mock Token contract from [`LEADER`]
319224
pub async fn deploy_token_contract(
320225
web3: &Web3<Http>,
321226
min_token_units: u64,
@@ -327,11 +232,7 @@ pub async fn deploy_token_contract(
327232
opt.gas_price = Some(1.into());
328233
opt.gas = Some(6_721_975.into());
329234
}))
330-
.execute(
331-
*MOCK_TOKEN_BYTECODE,
332-
(),
333-
H160(GANACHE_ADDRESSES["leader"].to_bytes()),
334-
)
235+
.execute(*MOCK_TOKEN_BYTECODE, (), H160(LEADER.to_bytes()))
335236
.await?;
336237

337238
let token_info = TokenInfo {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"0e880972a4b216906f05d67eeaaf55d16b5ee4f1","crypto":{"cipher":"aes-128-ctr","ciphertext":"a6517c853f41d70892195c2d49b6bf9cb70b28714df9148a2115422582ed71a7","cipherparams":{"iv":"29a072ed18b810e36461a4dafa3b8816"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"4647c8d015db3c67db397f291c13440b5a657f391470d02568c797d22252ee19"},"mac":"b9a6db84659a13b0d895418a9cff0a2b7b5f671ece4ea5c58b3c6cb403ad5a13"},"id":"be2aa04b-63d8-48ac-8d3b-3ed09a9d88b1","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"541b401362ea1d489d322579552b099e801f3632","crypto":{"cipher":"aes-128-ctr","ciphertext":"3bd972f8844c918ec26bdd4d3f8d22d9fe2f9d3451147ba938e343d927345d4f","cipherparams":{"iv":"5487bbad4c2b80bf3a92ecf7f28226ce"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"63a4ede118e5df870aafe733b209449ca8a68ba4e0996b95b6a2f35a527772cf"},"mac":"480b35a4cca3029ec50eb9179f192b8535f285b5f0eea4f36ca020109da73953"},"id":"b6be20d9-2e37-44fd-ad66-ac0c35433367","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"6b83e7d6b72c098d48968441e0d05658dc17adb9","crypto":{"cipher":"aes-128-ctr","ciphertext":"858809639fa1dbf62e75b4169cdc5943b5f45303bfe9b951521fc6693b1ce9a8","cipherparams":{"iv":"61bdcc7b9cd9d89fa96c56d9bff89f93"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"d5ecc7916286c175e8577282cd04ed261cce572f53a2a2305265025104a867c2"},"mac":"7796fbe5bd53dffb3e950f33cf925b4e514deb36f53aa2bc4168121172202dd7"},"id":"2a72e9cf-2641-452d-85f5-3a24cc4b3639","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"79d358a3194d737880b3efd94adccd246af9f535","crypto":{"cipher":"aes-128-ctr","ciphertext":"7476b220ad1319f5529db288ff3d28714036a08d4cbc8b4773576bbd441335f1","cipherparams":{"iv":"f1abaecd7c61b9a618e9d554f29663ab"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"de714bab560d07fa3c0fd65c91017c9f299ff81ba5452230efc992c8a45953c6"},"mac":"7859828865cf7475a406f3316a06484a19ca4731425ba32d69732b8669ab656a"},"id":"b3104849-29e1-4ae7-9f35-9d9416ecf800","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"80690751969b234697e9059e04ed72195c3507fa","crypto":{"cipher":"aes-128-ctr","ciphertext":"c2634ba60e6e06ecb93cc86cd01acaba46f20f6c0a8d0e7ee2369fc395d1e1da","cipherparams":{"iv":"59d357b9fc87ef7ca49cbdc05bb4d45a"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"044091f31212d7fcfe76cf1a900e809cbd2ffbde27d792f094217855194c3033"},"mac":"94b10daeec744c1ec9a420c87ba932ddd3d64eb91fe665ed38d8971c47baedcc"},"id":"6c42b310-341a-44d1-b878-4487820aa67c","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"dd589b43793934ef6ad266067a0d1d4896b0dff0","crypto":{"cipher":"aes-128-ctr","ciphertext":"c4098713be826e80f96def36c6c8712dde7d6d3e955041b266e6efff9130e94b","cipherparams":{"iv":"4650dad28bfb0d9004c289e9c449dfa9"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"072411161330f562f46a2acff9114cc6ed6d6e93e21b80cbb294ba5a2cc9663c"},"mac":"3e31a0891954b63590c9f94c626b5ecc555f96c4c6a50a5b9b90d84400ab40b4"},"id":"5cb4f686-fa3f-4aa6-a43b-ea413f37f5aa","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"e882ebf439207a70ddccb39e13ca8506c9f45fd9","crypto":{"cipher":"aes-128-ctr","ciphertext":"c2458d5ac69b72af7232e037a4cbda13f6c12b84ec28fba2a234e7a799ee6938","cipherparams":{"iv":"473f47d68e8d81ef61800fe49575a4b4"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"37836aae8dcbf65925f7d72c211caea16fc9e66c545ed5f4d53ee078d5322af0"},"mac":"9f77532bb970ed2a2007bb79e98cfc773a823308b49cc016ac37f8dfd20791f1"},"id":"7f46e65b-3fe0-4c89-8096-9ae1ee13fb52","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"acbada2d5830d1875ae3d2de207a1363b316df2f","crypto":{"cipher":"aes-128-ctr","ciphertext":"a0d31409ed0b0d7645184f9af9e1c604b496ab2723e937fa1041b0c2c1bf9039","cipherparams":{"iv":"162a6071a0a9d14a478aaec1651fff5d"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"0a9959172a7dfa8b2a9d991dcc807a1487710b8db4baea9cd94a013979d84d1c"},"mac":"123b89889ce16f8388b807d3b8edc9930533ce9f7283092b1f4a2e8e5c8e2b71"},"id":"9ff0e2f0-b047-4665-9739-c1f23c675921","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"e061e1eb461eabe512759aa18a201b20fe90631d","crypto":{"cipher":"aes-128-ctr","ciphertext":"2933df95448d0e38f7e1131470ab34ad3594c0350fa2aa609624e5f07ec0c234","cipherparams":{"iv":"3ce58291f69c56c12f82f4100db59f42"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"5c436a526de371d88ec969863c69fd2609343346518df7129db2ad42c57bc60a"},"mac":"bf3376d3b15faddc9ffbfd7bbac786879d0f915b37129290972f67d3c6843e6f"},"id":"ef2cf869-65fd-42d1-99dd-1cb5f0c62db6","version":3}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"address":"f3f583aec5f7c030722fe992a5688557e1b86ef7","crypto":{"cipher":"aes-128-ctr","ciphertext":"344d7cc0938dd957f26d051faf4a2bb1e2218c6a0e4bc34ff4a82a186bbdac64","cipherparams":{"iv":"5f21cb8d89daa243b1bc654754a35ec2"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"dfd642d19d7a7f1628e3d008b6567e3993c44b2109112ef3708a4ccd91e08bee"},"mac":"168df507bd8bb1de7bd09cf821dac0e3c1c2e4c099a77febb5255c2df537a449"},"id":"ef8571f7-a68a-4c6b-a595-78c4ec928908","version":3}

docker-compose.yml

-12
This file was deleted.

docs/config/ganache.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ ip_rate_limit = { type = 'ip', timeframe = 1200000 }
3030
sid_rate_limit = { type = 'sid', timeframe = 0 }
3131

3232
# Ganache Snapshot address
33-
outpace_address = '0xcb097e455b7159f902e2eb45562fc397ae6b0f3d'
33+
outpace_address = '0xabc27d46a458e2e49dabfef45ca74dedbac3dd06'
3434
# Ganache Snapshot address
35-
sweeper_address = '0xdd41b0069256a28972458199a3c9cf036384c156'
35+
sweeper_address = '0x7dd57c0324284102a757153e18f2cb1acdb7d2bd'
3636

3737
ethereum_network = 'http://localhost:8545'
3838
# Mocked relayer
@@ -45,11 +45,11 @@ validators_whitelist = []
4545

4646
[[token_address_whitelist]]
4747
# Mocked TOKEN
48-
address = '0x9db7bff788522dbe8fa2e8cbd568a58c471ccd5e'
48+
address = '0x2bcaf6968aec8a3b5126fbfab5fd419da6e8ad8e'
4949
# 1 * 10^18 = 1.0000 TOKEN
5050
min_token_units_for_deposit = '1000000000000000000'
51-
# multiplier = 10^14 - 10^18 (token precision) = 10^-4
52-
# min_validator_fee = 1 * 10^-4 = 0.000_1
53-
min_validator_fee = '100000000000000'
51+
# multiplier = 10^13 - 10^18 (token precision) = 10^-5
52+
# min_validator_fee = 1 * 10^-5 = 0.000_01
53+
min_validator_fee = '10000000000000'
5454
precision = 18
5555

lib/protocol-eth

Submodule protocol-eth updated 66 files

primitives/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ edition = "2021"
1010

1111
[features]
1212
postgres = ["bytes", "tokio-postgres", "deadpool-postgres"]
13+
# Enables the testing utilities like addresses, dummy Campaigns, Validators, IPFSes, AdUnits, etc.
14+
# All Addresses and keystore files exist in the ganache-cli setup for testing with the EthereumAdapter
15+
test-util = []
1316

1417
[dependencies]
1518
# (De)Serialization

0 commit comments

Comments
 (0)