Add tools

This commit is contained in:
Karl Kempe 2022-04-27 22:08:42 +00:00
parent 49ae859b03
commit f34ec5e991
7 changed files with 4372 additions and 152 deletions

View File

@ -10,6 +10,11 @@ clean:
cd ethereum && make clean
cd terra && make clean
cd sdk/js && rm -rf node_modules contracts lib src/icco/__tests__/tilt.json
<<<<<<< Updated upstream
=======
cd tools && rm -rf node_modules lib
rm -f tilt.json
>>>>>>> Stashed changes
.PHONY: ethereum
## Build Ethereum contracts
@ -27,18 +32,37 @@ terra/artifacts/checksum.txt:
.PHONY: sdk
## Build SDK
sdk: ethereum sdk/js/node_modules
sdk: sdk/js/lib
sdk/js/lib: ethereum sdk/js/node_modules
cd sdk/js && npm run build
sdk/js/node_modules:
cd sdk/js && npm ci
.PHONY: tools
## Build tools (scripts in tools directory)
tools: tools/lib
tools/lib: sdk
cd tools && npm ci && npm run build
.PHONY: tilt-deploy
## Deploy Contracts to Tilt
<<<<<<< Updated upstream
tilt-deploy: ethereum terra
@if ! pgrep tilt; then echo "Error: tilt not running. Start it before running tests"; exit 1; fi
cd ethereum && make tilt-deploy
cd ethereum && npx truffle exec scripts/register_tilt_contributors.js --network eth_devnet
=======
tilt-deploy: ethereum tools #terra
rm -f tilt.json
@if ! pgrep tilt; then echo "Error: tilt not running. Start it before running tests"; exit 1; fi
cd ethereum && make tilt-deploy
# cd ethereum && npx truffle exec scripts/register_tilt_contributors.js --network eth_devnet
node tools/lib/register_tilt_contributors.js
cp tilt.json sdk/js/src/icco/__tests__/tilt.json
>>>>>>> Stashed changes
.PHONY: tilt-test
## Run Integration Test in Tilt

View File

@ -1,151 +0,0 @@
---
apiVersion: v1
kind: Service
metadata:
name: eth-devnet
labels:
app: eth-devnet
spec:
ports:
- port: 8545
name: rpc
protocol: TCP
clusterIP: None
selector:
app: eth-devnet
---
apiVersion: v1
kind: Service
metadata:
name: eth-devnet2
labels:
app: eth-devnet2
spec:
ports:
- port: 8546
targetPort: 8545
name: rpc
protocol: TCP
clusterIP: None
selector:
app: eth-devnet2
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: eth-devnet
spec:
selector:
matchLabels:
app: eth-devnet
serviceName: eth-devnet
replicas: 1
template:
metadata:
labels:
app: eth-devnet
spec:
terminationGracePeriodSeconds: 1
containers:
- name: ganache
image: eth-node
command:
- npx
- ganache-cli
- -e 10000
- --deterministic
- --time="1970-01-01T00:00:00+00:00"
- --host=0.0.0.0
ports:
- containerPort: 8545
name: rpc
protocol: TCP
readinessProbe:
tcpSocket:
port: rpc
- name: tests
image: eth-node
stdin: true
command:
- /bin/sh
- -c
- "npm run migrate
&& npm run deploy-icco
&& npx truffle exec scripts/deploy_test_token.js
&& npx truffle exec scripts/register_solana_chain.js
&& npx truffle exec scripts/register_terra_chain.js
&& npx truffle exec scripts/register_bsc_chain.js
&& npx truffle exec scripts/register_contributors.js
&& nc -lkp 2000 0.0.0.0"
readinessProbe:
periodSeconds: 1
failureThreshold: 300
tcpSocket:
port: 2000
- name: mine
image: eth-node
command:
- /bin/sh
- -c
- "npx truffle exec mine.js"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: eth-devnet2
spec:
selector:
matchLabels:
app: eth-devnet2
serviceName: eth-devnet2
replicas: 1
template:
metadata:
labels:
app: eth-devnet2
spec:
terminationGracePeriodSeconds: 1
containers:
- name: ganache
image: eth-node
command:
- npx
- ganache-cli
- -e 10000
- --deterministic
- --time="1970-01-01T00:00:00+00:00"
- --host=0.0.0.0
- --chainId=1397
ports:
- containerPort: 8545
name: rpc
protocol: TCP
readinessProbe:
tcpSocket:
port: rpc
- name: tests
image: eth-node
stdin: true
command:
- /bin/sh
- -c
- "sed -i 's/CHAIN_ID=0x2/CHAIN_ID=0x4/g' .env
&& npm run migrate
&& sed -i 's/ICCO_CONDUCTOR_INIT_CHAIN_ID=0x4/ICCO_CONDUCTOR_INIT_CHAIN_ID=0x2/g' .env
&& npm run deploy-icco
&& npx truffle exec scripts/deploy_test_token.js
&& npx truffle exec scripts/register_solana_chain.js
&& npx truffle exec scripts/register_terra_chain.js
&& npx truffle exec scripts/register_eth_chain.js
&& nc -lkp 2000 0.0.0.0"
readinessProbe:
periodSeconds: 1
failureThreshold: 300
tcpSocket:
port: 2000
- name: mine
image: eth-node
command:
- /bin/sh
- -c
- "npx truffle exec mine.js"

2
tools/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
lib

4217
tools/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

25
tools/package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "tools",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"@types/node": "^16.6.1",
"ethers": "^5.4.4",
"prettier": "^2.3.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.3.5",
"wormhole-icco-sdk": "file:../sdk/js/lib/cjs"
},
"author": "",
"license": "ISC",
"dependencies": {
"@certusone/wormhole-sdk": "^0.2.5",
"@solana/web3.js": "^1.24.0"
}
}

View File

@ -0,0 +1,86 @@
import fs from "fs";
import {
ChainId,
CHAIN_ID_SOLANA,
CHAIN_ID_ETH,
CHAIN_ID_BSC,
hexToUint8Array,
} from "@certusone/wormhole-sdk";
import {
getContributorContractOnEth,
registerChainOnEth,
} from "wormhole-icco-sdk";
import { ethers } from "ethers";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const ETH_DEVNET_PK =
"0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"; // account 2
interface Emitter {
chainId: ChainId;
address: string;
}
async function main() {
const provider = new ethers.providers.StaticJsonRpcProvider(
"http://localhost:8545"
);
const wallet = new ethers.Wallet(ETH_DEVNET_PK, provider);
const tilt = JSON.parse(
fs.readFileSync(`${__dirname}/../../tilt.json`, "utf8")
);
const emitters: Emitter[] = [];
{
// TODO: grab this from the tilt.json file...
// const solanaProgAddr = "22mamxmojFWBdbGqaxTH46HBAgAY2bJRiGJJHfNRNQ95"; //TBD Not used, because I could not get WH sdk to be available in tilt.
const solanaEmitterAddr =
"aeab35a8d36bbaad38154ca4ca6a0770e7009326316d59ef2c8a2123e90d174c"; // Derived from solanaProgAddr using await sdk.getEmitterAddressSolana(..);
// Build chainId -> ContributorAddr map.
const ethEmitterAddress =
"000000000000000000000000" + tilt.ethContributorAddress.substring(2);
const bscEmitterAddress =
"000000000000000000000000" + tilt.bscContributorAddress.substring(2);
emitters.push({ chainId: CHAIN_ID_SOLANA, address: solanaEmitterAddr });
emitters.push({ chainId: CHAIN_ID_ETH, address: ethEmitterAddress });
emitters.push({ chainId: CHAIN_ID_BSC, address: bscEmitterAddress });
}
// register all chainId -> ContributorAddr with conductor.
for (const emitter of emitters) {
console.log(
"Registering chainId: ",
emitter.chainId,
" emitter: ",
emitter.address
);
const contributorAddress = hexToUint8Array(emitter.address);
const receipt = await registerChainOnEth(
tilt.conductorAddress,
emitter.chainId,
contributorAddress,
wallet
);
console.log("tx", receipt.blockHash);
const check = await getContributorContractOnEth(
tilt.conductorAddress,
provider,
emitter.chainId
);
console.log(check);
}
return;
}
main();

17
tools/tsconfig.json Normal file
View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
"outDir": "lib",
"strict": true,
"esModuleInterop": true,
"allowJs": true,
"resolveJsonModule": true
},
"include": ["register_tilt_contributors.ts"],
"exclude": [
"node_modules"
]
}