Skip to content

Commit b56c9ba

Browse files
authored
Merge pull request #482 from AmbireTech/issue-336-second-ganache-instance
Issue #336 Multi-chain support - run a second instance of ganache-cli with Chain Id #1
2 parents 3aa3346 + 4de5ef1 commit b56c9ba

File tree

374 files changed

+301
-57
lines changed

Some content is hidden

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

374 files changed

+301
-57
lines changed

adapter/Makefile.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ args = ["test", "--release", "--all-features"]
1818

1919
[tasks.ganache-up]
2020
script = '''
21-
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache \
21+
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache-1 ganache-1337 \
2222
&& sleep 10
2323
'''
2424

adapter/src/ethereum/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ mod test {
704704

705705
#[tokio::test]
706706
async fn get_deposit_and_count_create2_when_min_tokens_received() {
707-
let web3 = GANACHE_WEB3.clone();
707+
let web3 = GANACHE_1337_WEB3.clone();
708708

709709
let leader_account = *LEADER;
710710

adapter/src/ethereum/test_util.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ pub static KEYSTORES: Lazy<HashMap<Address, Options>> = Lazy::new(|| {
8888
.collect()
8989
});
9090

91-
/// Local `ganache` is running at:
92-
pub const GANACHE_URL: &str = "http://localhost:8545";
93-
9491
// /// [`Chain`] of the locally running `ganache-cli` chain with id #1
9592
pub static GANACHE_1: Lazy<Chain> = Lazy::new(|| GANACHE_INFO_1.chain.clone());
9693

@@ -117,7 +114,7 @@ pub static GANACHE_INFO_1337: Lazy<ChainInfo> = Lazy::new(|| {
117114

118115
/// Initialized Ganache [`Web3`] instance using a Http transport for usage in tests.
119116
/// It uses the [`GANACHE_1337`] to initialize the client.
120-
pub static GANACHE_WEB3: Lazy<Web3<Http>> = Lazy::new(|| {
117+
pub static GANACHE_1337_WEB3: Lazy<Web3<Http>> = Lazy::new(|| {
121118
GANACHE_1337
122119
.init_web3()
123120
.expect("Should init the Web3 client")

docker-compose.harness.yml

+24-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,34 @@ services:
2424
- "6379:6379"
2525
networks:
2626
- adex-external
27-
ganache:
28-
build: ./scripts/ethereum
27+
ganache-1:
28+
build:
29+
context: ./scripts/ethereum
30+
args:
31+
SNAPSHOT_CONTRACTS: snapshot_contracts_1
2932
image: adex-ganache
30-
container_name: adex-ganache-cli
33+
container_name: adex-ganache-cli-chain_id-1
3134
restart: always
3235
ports:
3336
- "8545:8545"
37+
environment:
38+
CHAIN_ID: 1
39+
networks:
40+
- adex-external
41+
# Chain Id 1337 - the default Ganache chain id
42+
ganache-1337:
43+
build:
44+
context: ./scripts/ethereum
45+
args:
46+
SNAPSHOT_CONTRACTS: snapshot_contracts_1337
47+
image: adex-ganache
48+
container_name: adex-ganache-cli-chain_id-1337
49+
restart: always
50+
ports:
51+
# use a different port for this second instance of ganache-cli
52+
- "1337:8545"
53+
environment:
54+
CHAIN_ID: 1337
3455
networks:
3556
- adex-external
3657

docs/config/ganache.toml

+13-33
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,17 @@ validators_whitelist = []
2828
# Leader - 0x80690751969B234697e9059e04ed72195c3507fa
2929
admins = ['0x80690751969B234697e9059e04ed72195c3507fa']
3030

31-
# Ethereum mainnet tokens
32-
# [chain."Ganache #1"]
33-
# # Ethereum Mainnet for testing
34-
# chain_id = 1
35-
# rpc = 'http://localhost:8546'
36-
# # Ganache Snapshot address
37-
# outpace = '0x0000000000000000000000000000000000000000'
38-
# # Ganache Snapshot address
39-
# sweeper = '0x0000000000000000000000000000000000000000'
40-
41-
# [chain."Ganache #1".token."Mocked TOKEN"]
42-
# address = '0x2bcaf6968aec8a3b5126fbfab5fd419da6e8ad8e' # checked
43-
# precision = 18
44-
# # Minimum token units for the Create2 deposits to count
45-
# # 1 * 10^18 = 1.0000 TOKEN
46-
# min_token_units_for_deposit = '1000000000000000000'
47-
# # multiplier = 10^12 - 10^18 (token precision) = 10^-6
48-
# # min_validator_fee = 1 * 10^-6 = 0.000_001
49-
# min_validator_fee = '1000000000000'
50-
51-
[chain."Ganache #1337"]
31+
[chain."Ganache #1"]
5232
# Ganache default chain id for testing
53-
chain_id = 1337
33+
chain_id = 1
5434
rpc = 'http://localhost:8545'
5535
# Ganache Snapshot address
56-
outpace = '0xAbc27d46a458E2e49DaBfEf45ca74dEDBAc3DD06'
36+
outpace = '0x671b54359be2fa82aB05A5336EB8134F782B88Cd'
5737
# Ganache Snapshot address
58-
sweeper = '0x7dD57C0324284102A757153E18F2Cb1ACdB7d2bD'
38+
sweeper = '0xE37BA12D23e755138f7Ea8391551B773Cb2D8F5F'
5939

60-
[chain."Ganache #1337".token."Mocked TOKEN"]
61-
address = '0x2bcaf6968aec8a3b5126fbfab5fd419da6e8ad8e' # checked
40+
[chain."Ganache #1".token."Mocked TOKEN 2"]
41+
address = '0x704D76a8c31FbAafE2B7895b13A763c7487FC0D8' # checked
6242
precision = 18
6343
# Minimum token units for the Create2 deposits to count
6444
# 1 * 10^18 = 1.0000 TOKEN
@@ -68,17 +48,17 @@ sweeper = '0x7dD57C0324284102A757153E18F2Cb1ACdB7d2bD'
6848
min_validator_fee = '1000000000000'
6949

7050

71-
[chain."Ganache #1"]
51+
[chain."Ganache #1337"]
7252
# Ganache default chain id for testing
73-
chain_id = 1
74-
rpc = 'http://localhost:8546'
53+
chain_id = 1337
54+
rpc = 'http://localhost:1337'
7555
# Ganache Snapshot address
76-
outpace = '0x0000000000000000000000000000000000000001'
56+
outpace = '0xAbc27d46a458E2e49DaBfEf45ca74dEDBAc3DD06'
7757
# Ganache Snapshot address
78-
sweeper = '0x0000000000000000000000000000000000000001'
58+
sweeper = '0x7dD57C0324284102A757153E18F2Cb1ACdB7d2bD'
7959

80-
[chain."Ganache #1".token."Mocked TOKEN 2"]
81-
address = '0x0000000000000000000000000000000000000001' # checked
60+
[chain."Ganache #1337".token."Mocked TOKEN"]
61+
address = '0x2bcaf6968aec8a3b5126fbfab5fd419da6e8ad8e' # checked
8262
precision = 18
8363
# Minimum token units for the Create2 deposits to count
8464
# 1 * 10^18 = 1.0000 TOKEN

scripts/ethereum/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ LABEL maintainer="[email protected]"
55

66
WORKDIR /scripts
77

8+
# The Chain Id that will be passed to `ganache-cli`
9+
ENV CHAIN_ID=
10+
# The snapshot contracts directory that will be used
11+
ARG SNAPSHOT_CONTRACTS=
12+
813
COPY ganache-cli.sh .
9-
COPY snapshot_contracts snapshot
14+
# Copy the SNAPSHOT_CONTRACTS directory to the /scripts/snapshot folder
15+
COPY ${SNAPSHOT_CONTRACTS} ./snapshot
1016

1117
EXPOSE 8545
1218

scripts/ethereum/ganache-cli.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636
#
3737
# gasLimit = 4503599627370495 (0xfffffffffffff)
3838
#
39+
40+
# Used to specify the chainId & snapshot folder of the contracts
41+
CHAIN_ID=${CHAIN_ID:-1337}
42+
3943
node /app/ganache-core.docker.cli.js --gasLimit 0xfffffffffffff \
40-
--chainId=1337 \
44+
--chainId=${CHAIN_ID} \
4145
--db="./snapshot" \
4246
--deterministic \
4347
--mnemonic="diary west sketch curious expose decade symptom height minor layer carry man" \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"header":{"parentHash":"0x59dd056c61376c3dc4bdfa7d9179eddace016f7098328287726a0415f7683d33","uncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","coinbase":"0x0000000000000000000000000000000000000000","stateRoot":"0x1bd138395965ae1808b14c362d8cfdf165fea7c247273d13c181f09325a26b25","transactionsTrie":"0xe156b0e6fc470ee242a87ba3ab46b29cf10fbd1017a2c9775056471dc957ba37","receiptTrie":"0x41d3cb5fd6e113debbe92b0ba67ff8c62ae8ad5b7bed3b87cf7f61a4fbe49694","bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","difficulty":"0x","number":"0x07","gasLimit":"0x0fffffffffffff","gasUsed":"0x09b2b3","timestamp":"0x6242d214","extraData":"0x","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000"},"transactions":[{"hash":"0xccc3dc16394f6e49334fbbb8160d3b0504699a8411cd050411fe494edb84d968","nonce":"0x6","from":"0x80690751969b234697e9059e04ed72195c3507fa","to":null,"value":"0x0","gas":"0x6691b7","gasPrice":"0x1","data":"608060405234801561001057600080fd5b50610a8f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063095ea7b31461006757806323b872dd1461009757806370a08231146100c7578063a2b0a1c7146100f7578063a9059cbb14610113578063dd62ed3e14610143575b600080fd5b610081600480360381019061007c919061081d565b610173565b60405161008e919061089a565b60405180910390f35b6100b160048036038101906100ac91906107ce565b6101c3565b6040516100be919061089a565b60405180910390f35b6100e160048036038101906100dc9190610769565b61045c565b6040516100ee91906108d5565b60405180910390f35b610111600480360381019061010c919061081d565b6104a4565b005b61012d6004803603810190610128919061081d565b6104eb565b60405161013a919061089a565b60405180910390f35b61015d60048036038101906101589190610792565b6106f5565b60405161016a91906108d5565b60405180910390f35b600081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015610246576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161023d906108b5565b60405180910390fd5b816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546102909190610957565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461031c9190610901565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411156103ec576000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161044991906108d5565b60405180910390a3600190509392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101561056e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610565906108b5565b60405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546105b89190610957565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546106449190610901565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516106e391906108d5565b60405180910390a36001905092915050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b60008135905061074e81610a2b565b92915050565b60008135905061076381610a42565b92915050565b60006020828403121561077b57600080fd5b60006107898482850161073f565b91505092915050565b600080604083850312156107a557600080fd5b60006107b38582860161073f565b92505060206107c48582860161073f565b9150509250929050565b6000806000606084860312156107e357600080fd5b60006107f18682870161073f565b93505060206108028682870161073f565b925050604061081386828701610754565b9150509250925092565b6000806040838503121561083057600080fd5b600061083e8582860161073f565b925050602061084f85828601610754565b9150509250929050565b6108628161099d565b82525050565b60006108756012836108f0565b915061088082610a02565b602082019050919050565b610894816109c9565b82525050565b60006020820190506108af6000830184610859565b92915050565b600060208201905081810360008301526108ce81610868565b9050919050565b60006020820190506108ea600083018461088b565b92915050565b600082825260208201905092915050565b600061090c826109c9565b9150610917836109c9565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561094c5761094b6109d3565b5b828201905092915050565b6000610962826109c9565b915061096d836109c9565b9250828210156109805761097f6109d3565b5b828203905092915050565b6000610996826109a9565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f494e53554646494349454e545f46554e44530000000000000000000000000000600082015250565b610a348161098b565b8114610a3f57600080fd5b50565b610a4b816109c9565b8114610a5657600080fd5b5056fea264697066735822122012d9e565a541ef14f604411fe60ee4679227706bb736ccd2d5aeb4962f73033e64736f6c63430008010033","v":"0x26","r":"0xfedccc2678a71aea5068e59c5d2bb1d4cf446deac241661faf7dd2b0c0227901","s":"0x7c137da31ddfca6673fe300896e6a662fee5b40cd3d06a8e6e940dbd9406889c","_type":1,"_options":{"hardfork":"muirGlacier","chainId":1,"networkId":1648546248174}}],"uncleHeaders":[]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"header":{"parentHash":"0x9da0d549f4a5cdf7ebe245ab26a3a8bd8fc4fc450c4f2905b1c77ae6b21d0114","uncleHash":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","coinbase":"0x0000000000000000000000000000000000000000","stateRoot":"0x941993414c6bdb351136bafaff3d72c7db63e7da5576cdc2cfd269f62af30eba","transactionsTrie":"0xf9ca29e9cd69f3fb9156bbf8ed17e54e1b6049bafa4640a703c9a8f8b3d92385","receiptTrie":"0x4593fa4b87f4619acddc3d13f088c63183cfecb80a59eb56dba0a958eeedb712","bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","difficulty":"0x","number":"0x08","gasLimit":"0x0fffffffffffff","gasUsed":"0x068070","timestamp":"0x6242d215","extraData":"0x","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000"},"transactions":[{"hash":"0xd8bd44e19e08e0098a3db76b6c8d5ce992a88545be689cfbf231320ad66cddcb","nonce":"0x7","from":"0x80690751969b234697e9059e04ed72195c3507fa","to":null,"value":"0x0","gas":"0x6691b7","gasPrice":"0x1","data":"608060405234801561001057600080fd5b506106c0806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a41283ff14610030575b600080fd5b61004361003e3660046101c5565b610045565b005b60005b8151811015610108576000801b8484848481518110610069576100696102da565b602002602001015160405161007d9061010e565b6001600160a01b03938416815282518416602080830191909152830151841660408083019190915280840151851660608084019190915284015185166080808401919091529093015160a0820152921660c083015251829181900360e001906000f59050801580156100f3573d6000803e3d6000fd5b50508080610100906102b1565b915050610048565b50505050565b61036c8061031f83390190565b600082601f83011261012c57600080fd5b8135602067ffffffffffffffff80831115610149576101496102f0565b8260051b604051601f19603f8301168101818110848211171561016e5761016e6102f0565b6040528481528381019250868401828801850189101561018d57600080fd5b600092505b858310156101b95780356101a581610306565b845292840192600192909201918401610192565b50979650505050505050565b600080600083850360e08112156101db57600080fd5b84356101e681610306565b935060a0601f19820112156101fa57600080fd5b50610203610288565b602085013561021181610306565b8152604085013561022181610306565b6020820152606085013561023481610306565b6040820152608085013561024781610306565b606082015260a08501356080820152915060c084013567ffffffffffffffff81111561027257600080fd5b61027e8682870161011b565b9150509250925092565b60405160a0810167ffffffffffffffff811182821017156102ab576102ab6102f0565b60405290565b60006000198214156102d357634e487b7160e01b600052601160045260246000fd5b5060010190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461031b57600080fd5b5056fe608060405234801561001057600080fd5b5060405161036c38038061036c83398101604081905261002f9161026f565b60608201516040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b15801561007557600080fd5b505afa158015610089573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100ad919061033a565b90506100c88360600151858361016660201b6100091760201c565b6040805163db6198a360e01b815284516001600160a01b03908116600483015260208601518116602483015291850151821660448201526060850151821660648201526080850151608482015283821660a482015260c481018390529085169063db6198a39060e401600060405180830381600087803b15801561014b57600080fd5b505af115801561015f573d6000803e3d6000fd5b5050505081ff5b60405163095ea7b360e01b81526001600160a01b0383811660048301526024820183905284169063095ea7b390604401600060405180830381600087803b1580156101b057600080fd5b505af11580156101c4573d6000803e3d6000fd5b505050506101d661022b60201b60201c565b6102265760405162461bcd60e51b815260206004820152601960248201527f5361666545524332303a20617070726f7665206661696c656400000000000000604482015260640160405180910390fd5b505050565b6000803d8015610242576020811461024b57610257565b60019150610257565b60206000803e60005191505b501515919050565b805161026a81610353565b919050565b600080600083850360e081121561028557600080fd5b845161029081610353565b935060a0601f19820112156102a457600080fd5b5060405160a081016001600160401b03811182821017156102d557634e487b7160e01b600052604160045260246000fd5b6040526102e46020860161025f565b81526102f26040860161025f565b60208201526103036060860161025f565b60408201526103146080860161025f565b606082015260a08501516080820152915061033160c0850161025f565b90509250925092565b60006020828403121561034c57600080fd5b5051919050565b6001600160a01b038116811461036857600080fd5b5056fea26469706673582212209bda0a08c5039854e5c8aa47fdd0644c803677908a9856e79538a97941fdd19964736f6c63430008070033","v":"0x26","r":"0xec6f77f6b60e186d69b3cdc108d40a102280125d5139e3d8ffd08f23c58aefaf","s":"0x5cdbce7b655b5eb2e26e6d404e526f4d0f60960f96cdcbb83d6e8ea9fe4538a1","_type":1,"_options":{"hardfork":"muirGlacier","chainId":1,"networkId":1648546248174}}],"uncleHeaders":[]}

0 commit comments

Comments
 (0)