Skip to content
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

ci and testing #468

Draft
wants to merge 1 commit into
base: v1.7.3-octopus
Choose a base branch
from
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ci/misbehaviour/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ memo_prefix = ''
# the account specified in `key_name` will pay the tx fees for all transactions
# submitted to this chain.
# fee_granter = ''
ic_endpoint = "http://localhost:4943"
canister_id = "bkyz2-fmaaa-aaaaa-qaaaq-cai"
canister_pem = "/home/boern/.config/dfx/identity/default/identity.pem"

[[chains]]
id = 'ibc-1'
Expand All @@ -317,3 +320,28 @@ max_block_time = '30s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }
ic_endpoint = "http://localhost:4943"
canister_id = "bkyz2-fmaaa-aaaaa-qaaaq-cai"
canister_pem = "/home/boern/.config/dfx/identity/default/identity.pem"

[[chains]]
type = 'near'
id = 'near-0'
near_ibc_address = "v5.nearibc.testnet"
rpc_addr = 'https://near-testnet.infura.io/v3/272532ecf0b64d7782a03db0cbcf3c30'
# rpc_addr = 'http://localhost:27030'
grpc_addr = 'http://localhost:27032'
event_source = { mode = 'push', url = 'ws://localhost:27030/websocket', batch_delay = '500ms' }
rpc_timeout = '15s'
account_prefix = 'cosmos'
key_name = 'wallet'
store_prefix = 'ibc'
gas_price = { price = 0.001, denom = 'stake' }
max_gas = 10000000
clock_drift = '5s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }

[chains.packet_filter]
policy = 'allow'
list = [['transfer', "channel-263"]]
28 changes: 28 additions & 0 deletions ci/misbehaviour/config_fork.toml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ memo_prefix = ''
# the account specified in `key_name` will pay the tx fees for all transactions
# submitted to this chain.
# fee_granter = ''
ic_endpoint = "http://localhost:4943"
canister_id = "bkyz2-fmaaa-aaaaa-qaaaq-cai"
canister_pem = "/home/boern/.config/dfx/identity/default/identity.pem"

[[chains]]
id = 'ibc-1'
Expand All @@ -316,3 +319,28 @@ max_block_time = '30s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }
address_type = { derivation = 'cosmos' }
ic_endpoint = "http://localhost:4943"
canister_id = "bkyz2-fmaaa-aaaaa-qaaaq-cai"
canister_pem = "/home/boern/.config/dfx/identity/default/identity.pem"

[[chains]]
type = 'near'
id = 'near-0'
near_ibc_address = "v5.nearibc.testnet"
rpc_addr = 'https://near-testnet.infura.io/v3/272532ecf0b64d7782a03db0cbcf3c30'
# rpc_addr = 'http://localhost:27030'
grpc_addr = 'http://localhost:27032'
event_source = { mode = 'push', url = 'ws://localhost:27030/websocket', batch_delay = '500ms' }
rpc_timeout = '15s'
account_prefix = 'cosmos'
key_name = 'wallet'
store_prefix = 'ibc'
gas_price = { price = 0.001, denom = 'stake' }
max_gas = 10000000
clock_drift = '5s'
trusting_period = '14days'
trust_threshold = { numerator = '1', denominator = '3' }

[chains.packet_filter]
policy = 'allow'
list = [['transfer', "channel-263"]]
22 changes: 19 additions & 3 deletions ci/misbehaviour/create_fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,25 @@ if [ -z "$(which sconfig)" ]; then
warn "Missing sconfig utility, install it from https://github.com/freshautomations/sconfig/releases"
exit 1
fi

if [ -z "$(which toml)" ]; then
warn "Missing toml utility, install it from https://github.com/gnprice/toml-cli"
exit 1
fi
# --- Main ---

info "Creating new channel between ibc-0 and ibc-1..."
$HERMES --config config.toml create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --new-client-connection --yes
info "Creating new channel between near-0 and ibc-1..."
$HERMES --config config.toml create channel --a-chain near-0 --b-chain ibc-1 --a-port transfer --b-port transfer --new-client-connection --yes

# update hermes config for near chain
CHANNEL_END="$($HERMES --config config.toml query channel end --chain ibc-1 --port transfer --channel channel-0 | grep channel- | cut -d'"' -f 2)"
echo
echo "New ibc channel: $CHANNEL_END"

new_config=$(toml set config.toml chains[2].packet_filter.list[0][1] $CHANNEL_END)
echo "$new_config" > config.toml
new_fork_config=$(toml set config_fork.toml chains[2].packet_filter.list[0][1] $CHANNEL_END)
echo "$new_fork_config" > config_fork.toml


info "Killing ibc-1..."
pkill -f ibc-1
Expand All @@ -47,8 +61,10 @@ sleep 5
info "Creating ibc-1 fork..."
cp -r data/ibc-1 data/ibc-1-f
sconfig data/ibc-1-f/config/config.toml "rpc.laddr=tcp://0.0.0.0:26457"
sconfig data/ibc-1-f/config/config.toml "rpc.pprof_laddr=localhost:6062"
sconfig data/ibc-1-f/config/config.toml "p2p.laddr=tcp://0.0.0.0:26456"


info "Starting ibc-1..."
gaiad --home ./data/ibc-1 start --pruning=nothing --grpc.address=0.0.0.0:9091 --log_level error > data/ibc-1.log 2>&1 &

Expand Down
14 changes: 10 additions & 4 deletions ci/misbehaviour/misbehaviour_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ sleep 10
info "Creating forked chain ibc-1-f"
bash ./create_fork.sh

info "Starting Hermes for ibc-0 and ibc-1"
CLIENT_ID="$($HERMES --config config.toml query connection end --chain ibc-1 --connection connection-0 | grep 07-tendermint- | cut -d'"' -f 2)"
echo
echo "New tendermint client id: $CLIENT_ID"

info "Starting Hermes for ibc-0,ibc-1,near-0"
$HERMES --config config.toml start > "$HERMES_LOG" 2>&1 &
HERMES_PID=$!
echo
echo "hermes pid: $HERMES_PID"

info "Waiting for Hermes to start"
sleep 10
sleep 15

info "Update client on ibc-0 against the forked chain ibc-1-f"
$HERMES --config config_fork.toml update client --client 07-tendermint-0 --host-chain ibc-0
info "Update client on near-0 against the forked chain ibc-1-f"
$HERMES --config config_fork.toml update client --client $CLIENT_ID --host-chain near-0

info "Wait for chain ibc-1 to stop..."
sleep 5
Expand Down
13 changes: 8 additions & 5 deletions scripts/one-chain
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,26 @@ sleep 1

# Add samoleans to user
USER=$($BINARY --home $CHAIN_DIR/$CHAIN_ID keys --keyring-backend="test" show user -a)
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $USER $USER_COINS &> /dev/null
$BINARY --home $CHAIN_DIR/$CHAIN_ID genesis add-genesis-account $USER $USER_COINS &> /dev/null
sleep 1

# Add samoleans to user2
USER2=$($BINARY --home $CHAIN_DIR/$CHAIN_ID keys --keyring-backend="test" show user2 -a)
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $USER2 $USER_COINS &> /dev/null
$BINARY --home $CHAIN_DIR/$CHAIN_ID genesis add-genesis-account $USER2 $USER_COINS &> /dev/null
sleep 1


# Add stake to validator
VALIDATOR=$($BINARY --home $CHAIN_DIR/$CHAIN_ID keys --keyring-backend="test" show validator -a)
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $VALIDATOR $STAKE &> /dev/null
$BINARY --home $CHAIN_DIR/$CHAIN_ID genesis add-genesis-account $VALIDATOR $STAKE &> /dev/null
sleep 1

# Stake everything
$BINARY --home $CHAIN_DIR/$CHAIN_ID gentx validator --keyring-backend="test" --chain-id $CHAIN_ID $STAKE &> /dev/null
$BINARY --home $CHAIN_DIR/$CHAIN_ID genesis gentx validator --keyring-backend="test" --chain-id $CHAIN_ID $STAKE &> /dev/null

sleep 1

$BINARY --home $CHAIN_DIR/$CHAIN_ID collect-gentxs &> /dev/null
$BINARY --home $CHAIN_DIR/$CHAIN_ID genesis collect-gentxs &> /dev/null
sleep 1

# Check platform
Expand All @@ -128,6 +129,7 @@ if [ $platform = 'linux' ]; then
sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '/^\[grpc-web\]/,/^\[/s/^enable = true/enable = false/' $CHAIN_DIR/$CHAIN_ID/config/app.toml
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.0001stake"/g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
else
sed -i '' 's#"172800s"#"200s"#g' $CHAIN_DIR/$CHAIN_ID/config/genesis.json
Expand All @@ -138,6 +140,7 @@ else
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' '/^\[grpc-web\]/,/^\[/s/^enable = true/enable = false/' $CHAIN_DIR/$CHAIN_ID/config/app.toml
sed -i '' 's/minimum-gas-prices = ""/minimum-gas-prices = "0.0001stake"/g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's/min-retain-blocks = 0/min-retain-blocks = 100/g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's/error/debug/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
Expand Down
1 change: 1 addition & 0 deletions tools/integration-test/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod query_packet;
pub mod supervisor;
pub mod tendermint;
pub mod ternary_transfer;
pub mod timeout;
pub mod transfer;

#[cfg(any(doc, feature = "ics29-fee"))]
Expand Down
179 changes: 179 additions & 0 deletions tools/integration-test/src/tests/timeout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use ibc_test_framework::ibc::denom::TaggedDenom;
use ibc_test_framework::prelude::*;
use ibc_test_framework::util::random::random_u128_range;
use std::thread;

#[test]
fn test_ibc_transfer_timeout_cosmos() -> Result<(), Error> {
run_binary_channel_test(&IbcTransferTimeoutCosmosTest)
}

#[test]
fn test_ibc_transfer_timeout_near() -> Result<(), Error> {
run_binary_channel_test(&IbcTransferTimeoutNearTest)
}

pub struct IbcTransferTimeoutCosmosTest;

impl TestOverrides for IbcTransferTimeoutCosmosTest {
fn should_spawn_supervisor(&self) -> bool {
false
}
}

impl BinaryChannelTest for IbcTransferTimeoutCosmosTest {
fn run<ChainA: ChainHandle, ChainB: ChainHandle>(
&self,
_config: &TestConfig,
relayer: RelayerDriver,
chains: ConnectedChains<ChainA, ChainB>,
channel: ConnectedChannel<ChainA, ChainB>,
) -> Result<(), Error> {
let token_contract = chains
.node_a
.chain_driver()
.setup_ibc_transfer_for_near(&channel.channel_id_a.0)?;

let wallet_a = chains.node_a.wallets().user1().cloned();
let wallet_b = chains.node_b.wallets().user1().cloned();

let balance_b = chains
.node_b
.chain_driver()
.query_balance(&wallet_b.address(), &chains.node_b.denom())?;

let b_to_a_amount = random_u128_range(1000, 5000);

let new_path = format!("{}/{}", "transfer", channel.channel_id_a.as_ref());

let ibc_denom_a: TaggedDenom<ChainA> = MonoTagged::new(Denom::Ibc {
path: new_path,
denom: "samoleans".to_string(),
hashed: token_contract.to_string(),
});

info!(
"Sending IBC transfer from chain {} to chain {} with amount of {}/samoleans",
chains.chain_id_b(),
chains.chain_id_a(),
b_to_a_amount,
);

chains
.node_b
.chain_driver()
.ibc_transfer_token_with_memo_and_timeout(
&channel.port_b.as_ref(),
&channel.channel_id_b.as_ref(),
&wallet_b.as_ref(),
&wallet_a.address(),
&chains.node_b.denom().with_amount(b_to_a_amount).as_ref(),
None,
Some(Duration::from_secs(5)),
)?;

chains.node_b.chain_driver().assert_eventual_wallet_amount(
&wallet_b.address(),
&(balance_b.clone() - b_to_a_amount).as_ref(),
)?;

// Sleep to wait for IBC packet to timeout before start relaying
thread::sleep(Duration::from_secs(6));

relayer.with_supervisor(|| {
chains.node_a.chain_driver().assert_eventual_wallet_amount(
&wallet_a.address(),
&ibc_denom_a.with_amount(0u128).as_ref(),
)?;

chains
.node_b
.chain_driver()
.assert_eventual_wallet_amount(&wallet_b.address(), &balance_b.as_ref())?;

Ok(())
})
}
}

pub struct IbcTransferTimeoutNearTest;

impl TestOverrides for IbcTransferTimeoutNearTest {
fn should_spawn_supervisor(&self) -> bool {
false
}
}

impl BinaryChannelTest for IbcTransferTimeoutNearTest {
fn run<ChainA: ChainHandle, ChainB: ChainHandle>(
&self,
_config: &TestConfig,
relayer: RelayerDriver,
chains: ConnectedChains<ChainA, ChainB>,
channel: ConnectedChannel<ChainA, ChainB>,
) -> Result<(), Error> {
chains
.node_a
.chain_driver()
.setup_ibc_transfer_for_near(&channel.channel_id_a.0)?;

let wallet_a = chains.node_a.wallets().user1().cloned();
let wallet_b = chains.node_b.wallets().user1().cloned();

let denom_a = chains.node_a.denom();
let balance_a = chains
.node_a
.chain_driver()
.query_balance(&wallet_a.address(), &denom_a)?;

let a_to_b_amount = random_u128_range(1, 10);

info!(
"Sending IBC transfer from chain {} to chain {} with amount of {}/samoleans",
chains.chain_id_a(),
chains.chain_id_b(),
a_to_b_amount,
);

chains
.node_a
.chain_driver()
.ibc_transfer_token_with_memo_and_timeout(
&channel.port_a.as_ref(),
&channel.channel_id_a.as_ref(),
&wallet_a.as_ref(),
&wallet_b.address(),
&denom_a.with_amount(a_to_b_amount).as_ref(),
None,
Some(Duration::from_secs(5)),
)?;

chains.node_a.chain_driver().assert_eventual_wallet_amount(
&wallet_a.address(),
&(balance_a.clone() - a_to_b_amount * 10u128.pow(18)).as_ref(),
)?;

let denom_b = derive_ibc_denom(
&channel.port_b.as_ref(),
&channel.channel_id_b.as_ref(),
&denom_a,
)?;

// Sleep to wait for IBC packet to timeout before start relaying
thread::sleep(Duration::from_secs(6));

relayer.with_supervisor(|| {
chains.node_b.chain_driver().assert_eventual_wallet_amount(
&wallet_b.address(),
&denom_b.with_amount(0u128).as_ref(),
)?;

chains
.node_a
.chain_driver()
.assert_eventual_wallet_amount(&wallet_a.address(), &(balance_a).as_ref())?;

Ok(())
})
}
}
Loading