Skip to content

Issue #336 Multi-chain support - run a second instance of ganache-cli with Chain Id #1 #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion adapter/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ args = ["test", "--release", "--all-features"]

[tasks.ganache-up]
script = '''
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache \
docker-compose -f ../docker-compose.harness.yml up --renew-anon-volumes -d ganache-1 ganache-1337 \
&& sleep 10
'''

Expand Down
2 changes: 1 addition & 1 deletion adapter/src/ethereum/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ mod test {

#[tokio::test]
async fn get_deposit_and_count_create2_when_min_tokens_received() {
let web3 = GANACHE_WEB3.clone();
let web3 = GANACHE_1337_WEB3.clone();

let leader_account = *LEADER;

Expand Down
5 changes: 1 addition & 4 deletions adapter/src/ethereum/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ pub static KEYSTORES: Lazy<HashMap<Address, Options>> = Lazy::new(|| {
.collect()
});

/// Local `ganache` is running at:
pub const GANACHE_URL: &str = "http://localhost:8545";

// /// [`Chain`] of the locally running `ganache-cli` chain with id #1
pub static GANACHE_1: Lazy<Chain> = Lazy::new(|| GANACHE_INFO_1.chain.clone());

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

/// Initialized Ganache [`Web3`] instance using a Http transport for usage in tests.
/// It uses the [`GANACHE_1337`] to initialize the client.
pub static GANACHE_WEB3: Lazy<Web3<Http>> = Lazy::new(|| {
pub static GANACHE_1337_WEB3: Lazy<Web3<Http>> = Lazy::new(|| {
GANACHE_1337
.init_web3()
.expect("Should init the Web3 client")
Expand Down
27 changes: 24 additions & 3 deletions docker-compose.harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,34 @@ services:
- "6379:6379"
networks:
- adex-external
ganache:
build: ./scripts/ethereum
ganache-1:
build:
context: ./scripts/ethereum
args:
SNAPSHOT_CONTRACTS: snapshot_contracts_1
image: adex-ganache
container_name: adex-ganache-cli
container_name: adex-ganache-cli-chain_id-1
restart: always
ports:
- "8545:8545"
environment:
CHAIN_ID: 1
networks:
- adex-external
# Chain Id 1337 - the default Ganache chain id
ganache-1337:
build:
context: ./scripts/ethereum
args:
SNAPSHOT_CONTRACTS: snapshot_contracts_1337
image: adex-ganache
container_name: adex-ganache-cli-chain_id-1337
restart: always
ports:
# use a different port for this second instance of ganache-cli
- "1337:8545"
environment:
CHAIN_ID: 1337
networks:
- adex-external

Expand Down
46 changes: 13 additions & 33 deletions docs/config/ganache.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,17 @@ validators_whitelist = []
# Leader - 0x80690751969B234697e9059e04ed72195c3507fa
admins = ['0x80690751969B234697e9059e04ed72195c3507fa']

# Ethereum mainnet tokens
# [chain."Ganache #1"]
# # Ethereum Mainnet for testing
# chain_id = 1
# rpc = 'http://localhost:8546'
# # Ganache Snapshot address
# outpace = '0x0000000000000000000000000000000000000000'
# # Ganache Snapshot address
# sweeper = '0x0000000000000000000000000000000000000000'

# [chain."Ganache #1".token."Mocked TOKEN"]
# address = '0x2bcaf6968aec8a3b5126fbfab5fd419da6e8ad8e' # checked
# precision = 18
# # Minimum token units for the Create2 deposits to count
# # 1 * 10^18 = 1.0000 TOKEN
# min_token_units_for_deposit = '1000000000000000000'
# # multiplier = 10^12 - 10^18 (token precision) = 10^-6
# # min_validator_fee = 1 * 10^-6 = 0.000_001
# min_validator_fee = '1000000000000'

[chain."Ganache #1337"]
[chain."Ganache #1"]
# Ganache default chain id for testing
chain_id = 1337
chain_id = 1
rpc = 'http://localhost:8545'
# Ganache Snapshot address
outpace = '0xAbc27d46a458E2e49DaBfEf45ca74dEDBAc3DD06'
outpace = '0x671b54359be2fa82aB05A5336EB8134F782B88Cd'
# Ganache Snapshot address
sweeper = '0x7dD57C0324284102A757153E18F2Cb1ACdB7d2bD'
sweeper = '0xE37BA12D23e755138f7Ea8391551B773Cb2D8F5F'

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


[chain."Ganache #1"]
[chain."Ganache #1337"]
# Ganache default chain id for testing
chain_id = 1
rpc = 'http://localhost:8546'
chain_id = 1337
rpc = 'http://localhost:1337'
# Ganache Snapshot address
outpace = '0x0000000000000000000000000000000000000001'
outpace = '0xAbc27d46a458E2e49DaBfEf45ca74dEDBAc3DD06'
# Ganache Snapshot address
sweeper = '0x0000000000000000000000000000000000000001'
sweeper = '0x7dD57C0324284102A757153E18F2Cb1ACdB7d2bD'

[chain."Ganache #1".token."Mocked TOKEN 2"]
address = '0x0000000000000000000000000000000000000001' # checked
[chain."Ganache #1337".token."Mocked TOKEN"]
address = '0x2bcaf6968aec8a3b5126fbfab5fd419da6e8ad8e' # checked
precision = 18
# Minimum token units for the Create2 deposits to count
# 1 * 10^18 = 1.0000 TOKEN
Expand Down
8 changes: 7 additions & 1 deletion scripts/ethereum/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ LABEL maintainer="[email protected]"

WORKDIR /scripts

# The Chain Id that will be passed to `ganache-cli`
ENV CHAIN_ID=
# The snapshot contracts directory that will be used
ARG SNAPSHOT_CONTRACTS=
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env. variables cannot be used in COPY, this is why we are passing a build argument of the snapshot directory that will be loaded by Ganache-cli


COPY ganache-cli.sh .
COPY snapshot_contracts snapshot
# Copy the SNAPSHOT_CONTRACTS directory to the /scripts/snapshot folder
COPY ${SNAPSHOT_CONTRACTS} ./snapshot

EXPOSE 8545

Expand Down
6 changes: 5 additions & 1 deletion scripts/ethereum/ganache-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
#
# gasLimit = 4503599627370495 (0xfffffffffffff)
#

# Used to specify the chainId & snapshot folder of the contracts
CHAIN_ID=${CHAIN_ID:-1337}

node /app/ganache-core.docker.cli.js --gasLimit 0xfffffffffffff \
--chainId=1337 \
--chainId=${CHAIN_ID} \
--db="./snapshot" \
--deterministic \
--mnemonic="diary west sketch curious expose decade symptom height minor layer carry man" \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8
1 change: 1 addition & 0 deletions scripts/ethereum/snapshot_contracts_1/!blockLogs!7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions scripts/ethereum/snapshot_contracts_1/!blockLogs!8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions scripts/ethereum/snapshot_contracts_1/!blockLogs!9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions scripts/ethereum/snapshot_contracts_1/!blockLogs!length
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
1 change: 1 addition & 0 deletions scripts/ethereum/snapshot_contracts_1/!blocks!7
Original file line number Diff line number Diff line change
@@ -0,0 +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":[]}
1 change: 1 addition & 0 deletions scripts/ethereum/snapshot_contracts_1/!blocks!8
Original file line number Diff line number Diff line change
@@ -0,0 +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":[]}
Loading