-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f601c5c
commit 8ba4a05
Showing
4 changed files
with
430 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
name: Integration_test_ibc | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test-e2e: | ||
name: End-to-end Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Golang | ||
uses: actions/setup-go@v2 | ||
|
||
- name: Checkout current repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Checkout leejw51crypto/ibc-rs | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: leejw51crypto/ibc-rs | ||
ref: ibc | ||
path: hermes-rs | ||
submodules: recursive | ||
|
||
- name: Checkout `chain-main` repository | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: crypto-org-chain/chain-main | ||
path: chain-main | ||
ref: v3.1.1 | ||
submodules: recursive | ||
|
||
- name: Build and start CHAIN_1 | ||
run: | | ||
sudo apt-get install jq | ||
mkdir ./chain2 && mkdir ./chain1 | ||
cp -r chain-main/* ./chain1/ | ||
cp -r chain-main/* ./chain2/ | ||
## Setup, configure and start `chain1` | ||
cd ./chain1 | ||
rm -rf $CHAIN_1_HOME | ||
export CHAIN_1_HOME=$PWD/chain1_data | ||
export CHAIN_1_ID=testnet1 | ||
export CHAIN_1_MONIKER=chain1 | ||
export ETHCONFIG=$CHAIN_1_HOME/config/config.toml | ||
export GENESIS=$CHAIN_1_HOME/config/genesis.json | ||
export TMPGENESIS=$CHAIN_1_HOME/config/tmp_genesis.json | ||
export APPCONFIG=$CHAIN_1_HOME/config/app.toml | ||
export CLIENTCONFIG=$CHAIN_1_HOME/config/client.toml | ||
export DENOM=denomone | ||
export CLI=./build/chain-maind | ||
export VALIDATOR_MNEMONIC="whale dry improve icon perfect sauce lesson wire oblige gadget exhaust toast spin enforce labor logic giraffe feed project weasel absent build reject life" | ||
export ECOSYSTEM_MNEMONIC="rubber rocket snack author mad ship core physical arrange language enrich story lamp move dynamic into game marine ramp trap anchor beyond mystery gun" | ||
export TOTALAMOUNT=100000000000000000000000000000000$DENOM | ||
export MYAMOUNT=1000100000000000000001$DENOM | ||
NETWORK=testnet make install | ||
NETWORK=testnet make build | ||
$CLI config keyring-backend test --home $CHAIN_1_HOME | ||
$CLI config chain-id $CHAIN_1_ID --home $CHAIN_1_HOME | ||
$CLI init $CHAIN_1_MONIKER --chain-id $CHAIN_1_ID --home $CHAIN_1_HOME | ||
echo $VALIDATOR_MNEMONIC | $CLI keys add validator --keyring-backend test --recover --index 0 --home $CHAIN_1_HOME | ||
echo $ECOSYSTEM_MNEMONIC | $CLI keys add ecosystem --keyring-backend test --recover --index 1 --home $CHAIN_1_HOME | ||
# $CLI keys add validator --keyring-backend test --home $CHAIN_1_HOME --output json >> ./validator.json | ||
# $CLI keys add ecosystem --keyring-backend test --home $CHAIN_1_HOME --output json >> ./ecosystem.json | ||
# Change parameter token denominations to $DENOM | ||
cat $GENESIS | jq '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
cat $GENESIS | jq '.app_state["crisis"]["constant_fee"]["denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
cat $GENESIS | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
cat $GENESIS | jq '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
# increase block time (?) | ||
cat $GENESIS | jq '.consensus_params["block"]["time_iota_ms"]="1000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
# Set gas limit in genesis | ||
cat $GENESIS | jq '.consensus_params["block"]["max_gas"]="10000000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
# Allocate genesis accounts (cosmos formatted addresses) | ||
$CLI add-genesis-account $($CLI keys show validator -a --keyring-backend test --home $CHAIN_1_HOME) $TOTALAMOUNT --keyring-backend test --home $CHAIN_1_HOME | ||
$CLI add-genesis-account $($CLI keys show ecosystem -a --keyring-backend test --home $CHAIN_1_HOME) $MYAMOUNT --keyring-backend test --home $CHAIN_1_HOME | ||
$CLI gentx validator $MYAMOUNT --keyring-backend test --chain-id $CHAIN_1_ID --home $CHAIN_1_HOME | ||
$CLI collect-gentxs --home $CHAIN_1_HOME | ||
$CLI validate-genesis --home $CHAIN_1_HOME | ||
$CLI start --pruning=nothing --trace --log_level info --minimum-gas-prices=0.0001$DENOM --home $CHAIN_1_HOME & | ||
- name: Build and start CHAIN_2 | ||
run: | | ||
## Setup, configure and start `chain2` | ||
cd ./chain2 | ||
rm -rf $CHAIN_2_HOME | ||
export CHAIN_2_HOME=$PWD/chain2_data | ||
export CHAIN_2_ID=testnet2 | ||
export CHAIN_2_MONIKER=chain2 | ||
export ETHCONFIG=$CHAIN_2_HOME/config/config.toml | ||
export GENESIS=$CHAIN_2_HOME/config/genesis.json | ||
export TMPGENESIS=$CHAIN_2_HOME/config/tmp_genesis.json | ||
export APPCONFIG=$CHAIN_2_HOME/config/app.toml | ||
export CLIENTCONFIG=$CHAIN_2_HOME/config/client.toml | ||
export CLI=./build/chain-maind | ||
export VALIDATOR_MNEMONIC="whale dry improve icon perfect sauce lesson wire oblige gadget exhaust toast spin enforce labor logic giraffe feed project weasel absent build reject life" | ||
export ECOSYSTEM_MNEMONIC="rubber rocket snack author mad ship core physical arrange language enrich story lamp move dynamic into game marine ramp trap anchor beyond mystery gun" | ||
# New node ports and hosts | ||
export DENOM_2=denomtwo | ||
export GRPCPORT0=9080 | ||
export GRPCPORT1=9081 | ||
export ETHPORT0=8535 | ||
export ETHPORT1=8536 | ||
export COSMOSPORT0=26646 | ||
export COSMOSPORT1=26647 | ||
export NODE=tcp://127.0.0.1:26707 | ||
export TOTALAMOUNT=200000000000000000000000000000000$DENOM_2 | ||
export MYAMOUNT=2000200000000000000001$DENOM_2 | ||
NETWORK=testnet make install | ||
NETWORK=testnet make build | ||
$CLI config keyring-backend test --home $CHAIN_2_HOME | ||
$CLI config chain-id $CHAIN_2_ID --home $CHAIN_2_HOME | ||
$CLI init $CHAIN_2_MONIKER --chain-id $CHAIN_2_ID --home $CHAIN_2_HOME | ||
echo $VALIDATOR_MNEMONIC | $CLI keys add validator --keyring-backend test --recover --index 0 --home $CHAIN_2_HOME | ||
echo $ECOSYSTEM_MNEMONIC | $CLI keys add ecosystem --keyring-backend test --recover --index 1 --home $CHAIN_2_HOME | ||
# $CLI keys add validator --keyring-backend test --home $CHAIN_2_HOME --output json >> ./validator.json | ||
# $CLI keys add ecosystem --keyring-backend test --home $CHAIN_2_HOME --output json >> ./ecosystem.json | ||
# Change parameter token denominations to $DENOM_2 | ||
cat $GENESIS | jq '.app_state["staking"]["params"]["bond_denom"]="'$DENOM_2'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
cat $GENESIS | jq '.app_state["crisis"]["constant_fee"]["denom"]="'$DENOM_2'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
cat $GENESIS | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="'$DENOM_2'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
cat $GENESIS | jq '.app_state["mint"]["params"]["mint_denom"]="'$DENOM_2'"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
# increase block time (?) | ||
cat $GENESIS | jq '.consensus_params["block"]["time_iota_ms"]="1000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
# Set gas limit in genesis | ||
cat $GENESIS | jq '.consensus_params["block"]["max_gas"]="10000000"' > $TMPGENESIS && mv $TMPGENESIS $GENESIS | ||
# change port | ||
sed -i "s/create_empty_blocks = true/create_empty_blocks = false/g" $ETHCONFIG | ||
sed -i "s/26657/$COSMOSPORT1/g" $CLIENTCONFIG | ||
sed -i "s/26657/$COSMOSPORT1/g" $ETHCONFIG | ||
sed -i "s/26656/$COSMOSPORT0/g" $ETHCONFIG | ||
sed -i "s/9090/$GRPCPORT0/g" $APPCONFIG | ||
sed -i "s/9091/$GRPCPORT1/g" $APPCONFIG | ||
sed -i "s/8545/$ETHPORT0/g" $APPCONFIG | ||
sed -i "s/8546/$ETHPORT1/g" $APPCONFIG | ||
sed -i "s/aphoton/$DENOM_2/g" $APPCONFIG | ||
sed -i "s/aphoton/$DENOM_2/g" $GENESIS | ||
# Allocate genesis accounts (cosmos formatted addresses) | ||
$CLI add-genesis-account $($CLI keys show validator -a --keyring-backend test --home $CHAIN_2_HOME) $TOTALAMOUNT --keyring-backend test --home $CHAIN_2_HOME | ||
$CLI add-genesis-account $($CLI keys show ecosystem -a --keyring-backend test --home $CHAIN_2_HOME) $MYAMOUNT --keyring-backend test --home $CHAIN_2_HOME | ||
$CLI gentx validator $MYAMOUNT --keyring-backend test --chain-id $CHAIN_2_ID --home $CHAIN_2_HOME | ||
$CLI collect-gentxs --home $CHAIN_2_HOME | ||
$CLI validate-genesis --home $CHAIN_2_HOME | ||
$CLI start --pruning=nothing --trace --log_level info --minimum-gas-prices=0.0001$DENOM_2 --home $CHAIN_2_HOME & | ||
- name: Ping and check both the networks | ||
run: | | ||
## Sleep 5 Seconds | ||
sleep 5 | ||
# Network 1 : chain1 | Should return `network1` & `chain1` | ||
curl --location --request GET 'localhost:26657/status' | jq '.result' | ||
# Network 2 : chain2 | Should return `network2` & `chain2` | ||
curl --location --request GET 'localhost:26647/status' | jq '.result' | ||
- name: Setup hermes | ||
run: | | ||
wget -q -O hermes.tar.gz https://github.com/informalsystems/ibc-rs/releases/download/v0.7.0/hermes-v0.7.0-x86_64-unknown-linux-gnu.tar.gz | ||
mkdir -p $HOME/.hermes/bin | ||
tar -C $HOME/.hermes/bin/ -xzf hermes.tar.gz | ||
export PATH="$HOME/.hermes/bin:$PATH" | ||
cp workflowConfig/config.toml ./hermes-rs | ||
cd hermes-rs | ||
export MYIBC0=testnet1 | ||
export MYIBC1=testnet2 | ||
export MYCHANNEL=channel-0 | ||
export MYCONFIG=$PWD/config.toml | ||
cat $MYCONFIG | ||
hermes -c $MYCONFIG keys restore $MYIBC0 -m "whale dry improve icon perfect sauce lesson wire oblige gadget exhaust toast spin enforce labor logic giraffe feed project weasel absent build reject life" -p "m/44'/1'/0'/0/0" | ||
hermes -c $MYCONFIG keys restore $MYIBC1 -m "whale dry improve icon perfect sauce lesson wire oblige gadget exhaust toast spin enforce labor logic giraffe feed project weasel absent build reject life" -p "m/44'/1'/0'/0/0" | ||
hermes -c $MYCONFIG keys list $MYIBC0 | ||
hermes -c $MYCONFIG keys list $MYIBC1 | ||
hermes -c $MYCONFIG create channel $MYIBC0 $MYIBC1 --port-a transfer --port-b transfer | ||
hermes -c $MYCONFIG start & | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
|
||
- uses: actions/cache@v2 | ||
id: cache-deps | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-node${{ matrix.code }}-${{ hashFiles('**/package-lock.json') }} | ||
|
||
- name: Run e2e test suite | ||
run: | | ||
npm install --no-progress --silent --quiet | ||
npm run test:e2e:ibc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* eslint-disable */ | ||
import 'mocha'; | ||
import Big from 'big.js'; | ||
import { expect } from 'chai'; | ||
import { assertIsBroadcastTxSuccess } from '@cosmjs/stargate'; | ||
import axios from 'axios'; | ||
|
||
import { HDKey } from '../src/hdkey/hdkey'; | ||
import { Secp256k1KeyPair } from '../src/keypair/secp256k1'; | ||
import { CroSDK } from '../src/core/cro'; | ||
import { Units } from '../src/coin/coin'; | ||
import { Network } from '../src/network/network'; | ||
import { SIGN_MODE } from '../src/transaction/types'; | ||
import Long from 'long'; | ||
|
||
const customNetwork: Network = { | ||
defaultNodeUrl: 'http://localhost', | ||
chainId: 'testnet', | ||
addressPrefix: 'tcro', | ||
validatorAddressPrefix: 'tcrocncl', | ||
validatorPubKeyPrefix: 'tcrocnclconspub', | ||
coin: { | ||
baseDenom: 'basetcro', | ||
croDenom: 'tcro', | ||
}, | ||
bip44Path: { | ||
coinType: 1, | ||
account: 0, | ||
}, | ||
rpcUrl: 'http://localhost:26657', | ||
}; | ||
|
||
const testNode = { | ||
httpEndpoint: 'localhost', | ||
httpPort: '26657', | ||
}; | ||
|
||
const axiosConfig = { | ||
method: 'get', | ||
url: `http://${testNode.httpEndpoint}:${testNode.httpPort}`, | ||
}; | ||
const env = { | ||
validatorOperatorAddress: process.env.VALIDATOR_OPERATOR_ADDRESS || '', | ||
mnemonic: { | ||
communityAccount: | ||
process.env.COMMUNITY_ACCOUNT_MNEMONIC || | ||
'play release domain walnut sword reason few fish sketch radio fancy since zebra exhibit boring army green suggest behind correct neither useful cruel type', | ||
reserveAccount: | ||
process.env.RESERVE_ACCOUNT_MNEMONIC || | ||
'improve speak symbol relax eyebrow vintage load grief huge wild doctor novel use borrow inch sweet symptom script nuclear drastic green corn phrase razor', | ||
ecosystemAccount: | ||
process.env.ECOSYSTEM_ACCOUNT_MNEMONIC || | ||
'rubber rocket snack author mad ship core physical arrange language enrich story lamp move dynamic into game marine ramp trap anchor beyond mystery gun', | ||
validatorAccount: | ||
process.env.VALIDATOR_ACCOUNT_MNEMONIC || | ||
'whale dry improve icon perfect sauce lesson wire oblige gadget exhaust toast spin enforce labor logic giraffe feed project weasel absent build reject life', | ||
randomEmptyAccount: HDKey.generateMnemonic(12), | ||
}, | ||
}; | ||
|
||
describe('e2e tests for IBC transactions', function () { | ||
it('[IBC] Creates, signs(protobuf) and broadcasts a `MsgTransfer` IBC Tx', async function () { | ||
const hdKey = HDKey.fromMnemonic(env.mnemonic.validatorAccount); | ||
const privKey = hdKey.derivePrivKey(`m/44'/${customNetwork.bip44Path.coinType}'/0'/0/0`); | ||
|
||
const keyPair = Secp256k1KeyPair.fromPrivKey(privKey); | ||
|
||
const cro = CroSDK({ network: customNetwork }); | ||
const address1 = new cro.Address(keyPair.getPubKey()); | ||
const tokenAmount = cro.v2.CoinV2.fromCustomAmountDenom('123456789', 'denomone'); | ||
const timeoutHeight = { | ||
revisionNumber: Long.fromString('0'), | ||
revisionHeight: Long.fromString('1708515'), | ||
}; | ||
const msgTransferIBCProtobuf = new cro.ibc.MsgTransfer({ | ||
sourcePort: 'transfer', | ||
sourceChannel: 'channel-0', | ||
token: tokenAmount, | ||
sender: 'tcro1rm0etys4apkaa4v3w462q72rr74he8trfchsfn', | ||
receiver: 'tcro1rm0etys4apkaa4v3w462q72rr74he8trfchsfn', | ||
timeoutHeight, | ||
timeoutTimestampInNanoSeconds: Long.fromString('1999620640362229420996'), | ||
}); | ||
|
||
const client = await cro.CroClient.connect(); | ||
|
||
expect(client).to.be.not.undefined; | ||
const account = await client.getAccount(address1.account()); | ||
const anySigner = { | ||
publicKey: keyPair.getPubKey(), | ||
accountNumber: new Big(account!.accountNumber), | ||
accountSequence: new Big(account!.sequence), | ||
}; | ||
const rawTx = new cro.RawTransaction(); | ||
const signableTx = rawTx.appendMessage(msgTransferIBCProtobuf).addSigner(anySigner).toSignable(); | ||
|
||
const signedTx = signableTx.setSignature(0, keyPair.sign(signableTx.toSignDocumentHash(0))).toSigned(); | ||
|
||
const broadcast = await axios.get('broadcast_tx_commit', { | ||
baseURL: axiosConfig.url, | ||
params: { tx: `0x${signedTx.getHexEncoded()}` }, | ||
}); | ||
expect(broadcast.status).to.eq(200); | ||
expect(broadcast.data).to.be.not.undefined; | ||
assertIsBroadcastTxSuccess(broadcast.data); | ||
}); | ||
it('[IBC] `MsgTransfer` IBC Tx using Amino', async function () { | ||
const hdKey = HDKey.fromMnemonic(env.mnemonic.validatorAccount); | ||
const privKey = hdKey.derivePrivKey(`m/44'/${customNetwork.bip44Path.coinType}'/0'/0/0`); | ||
|
||
const keyPair = Secp256k1KeyPair.fromPrivKey(privKey); | ||
|
||
const cro = CroSDK({ network: customNetwork }); | ||
const address1 = new cro.Address(keyPair.getPubKey()); | ||
const tokenAmount = cro.v2.CoinV2.fromCustomAmountDenom('123456789', 'denomone'); | ||
const timeoutHeight = { | ||
revisionNumber: Long.fromString('0'), | ||
revisionHeight: Long.fromString('1708515'), | ||
}; | ||
const msgTransferIBCProtobuf = new cro.ibc.MsgTransfer({ | ||
sourcePort: 'transfer', | ||
sourceChannel: 'channel-0', | ||
token: tokenAmount, | ||
sender: 'tcro1rm0etys4apkaa4v3w462q72rr74he8trfchsfn', | ||
receiver: 'tcro1rm0etys4apkaa4v3w462q72rr74he8trfchsfn', | ||
timeoutHeight, | ||
timeoutTimestampInNanoSeconds: Long.fromString('1999620640362229420996'), | ||
}); | ||
|
||
const client = await cro.CroClient.connect(); | ||
|
||
expect(client).to.be.not.undefined; | ||
const account = await client.getAccount(address1.account()); | ||
const anySigner = { | ||
publicKey: keyPair.getPubKey(), | ||
accountNumber: new Big(account!.accountNumber), | ||
accountSequence: new Big(account!.sequence), | ||
signMode: SIGN_MODE.LEGACY_AMINO_JSON, | ||
}; | ||
const rawTx = new cro.RawTransaction(); | ||
const signableTx = rawTx.appendMessage(msgTransferIBCProtobuf).addSigner(anySigner).toSignable(); | ||
|
||
const signedTx = signableTx.setSignature(0, keyPair.sign(signableTx.toSignDocumentHash(0))).toSigned(); | ||
|
||
const broadcast = await axios.get('broadcast_tx_commit', { | ||
baseURL: axiosConfig.url, | ||
params: { tx: `0x${signedTx.getHexEncoded()}` }, | ||
}); | ||
expect(broadcast.status).to.eq(200); | ||
expect(broadcast.data).to.be.not.undefined; | ||
assertIsBroadcastTxSuccess(broadcast.data); | ||
}); | ||
}); |
Oops, something went wrong.