Skip to content

Commit

Permalink
feat: add anvil to docker-compose and reconfigure deploy script
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Nov 1, 2023
1 parent b0379a3 commit 5598385
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ $ forge test
```shell
$ forge fmt
```

## Local Testnet

To deploy the relay contract to a local environment for testing use our convenience script [here](./sdk/scripts/init-bridge.ts):

```shell
# start local ethereum testnet node
docker-compose up anvil
# run script to deploy the relay contract
cd sdk
yarn run deploy-relay --init-height 2016 --private-key dev-0 --dev --network testnet
```

The initialization height should be a multiple of 2016 with at least one subsequent retarget (i.e. if using 2016 as the starting height, blocks 4031-4032 must exist).
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ services:
ports:
- "3002:3002"
restart: always

anvil:
image: "ghcr.io/foundry-rs/foundry:latest"
entrypoint:
- anvil
- --host
- "0.0.0.0"
- --chain-id
- "901"
ports:
- "8545:8545"
restart: always
54 changes: 40 additions & 14 deletions sdk/scripts/init-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@ const args = yargs(hideBin(process.argv))
description: "Private key to submit with",
type: "string",
demandOption: true,
}).argv;
})
.option("dev", {
description: "Deploy the contracts locally",
type: "boolean",
})
.option("network", {
description: "Bitcoin network to use",
type: "string",
demandOption: true,
})
.argv;

main().catch((err) => {
console.log("Error thrown by script:");
console.log(err);
});


async function main(): Promise<void> {
const electrs = new DefaultElectrsClient("testnet");
// args["parachain-endpoint"]
const electrs = new DefaultElectrsClient(args["network"]);

const initHeight = args["init-height"];
const privateKey = args["private-key"];
if ((initHeight % 2016) != 0) {
throw new Error("Invalid genesis height: must be multiple of 2016");
}
Expand All @@ -40,15 +48,33 @@ async function main(): Promise<void> {
console.log(`Genesis: ${genesis}`);
console.log(`beforeRetarget: ${beforeRetarget}`);
console.log(`afterRetarget: ${afterRetarget}`);


exec(`GENESIS_HEIGHT=${initHeight} GENESIS_HEADER=${genesis} RETARGET_HEADERS=${beforeRetarget}${afterRetarget} PRIVATE_KEY=${privateKey} forge script script/Bridge.s.sol:BridgeScript --rpc-url 'https://l2-fluffy-bob-7mjgi9pmtg.t.conduit.xyz' --chain 901 --verify --verifier blockscout --verifier-url 'https://explorerl2-fluffy-bob-7mjgi9pmtg.t.conduit.xyz/api?' --broadcast`,
let rpcUrl: string;
let verifyOpts: string | undefined;
if (args["dev"]) {
rpcUrl = "http://localhost:8545";
} else {
rpcUrl = "http://l2-fluffy-bob-7mjgi9pmtg.t.conduit.xyz";
verifyOpts = "--verify --verifier blockscout --verifier-url 'https://explorerl2-fluffy-bob-7mjgi9pmtg.t.conduit.xyz/api?'";
}

let privateKey: string;
switch (args["private-key"]) {
case "dev-0":
privateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
break;
default:
privateKey = args["private-key"];
break;
}

exec(`GENESIS_HEIGHT=${initHeight} GENESIS_HEADER=${genesis} RETARGET_HEADERS=${beforeRetarget}${afterRetarget} PRIVATE_KEY=${privateKey} forge script ../script/Bridge.s.sol:BridgeScript --rpc-url '${rpcUrl}' --chain 901 ${verifyOpts} --broadcast`,
(err: any, stdout: any, stderr: any) => {
if (err) {
throw new Error(`Failed to run command: ${err}`);
}
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
});
if (err) {
throw new Error(`Failed to run command: ${err}`);
}

// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
});
}

0 comments on commit 5598385

Please sign in to comment.