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

test: integration test #300

Merged
merged 10 commits into from
Jan 9, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ ictest-all: ictest-start-cosmos ictest-ibc
### Integration Tests ###
###############################################################################

#./scripts/tests/relayer/interchain-acc-config/rly-init.sh

integration-test-all: init-test-framework \
test-ica \
test-ibc-hooks \
test-alliance \
test-tokenfactory

init-test-framework: clean-testing-data install
@echo "Initializing both blockchains..."
./scripts/tests/init-test-framework.sh
Expand All @@ -162,9 +166,20 @@ test-tokenfactory:
@echo "Testing tokenfactory..."
./scripts/tests/tokenfactory/tokenfactory.sh

test-alliance:
@echo "Testing alliance..."
./scripts/tests/alliance/delegate.sh

test-ica:
@echo "Testing ica..."
./scripts/tests/ica/delegate.sh

test-ibc-hooks:
@echo "Testing ibc-hooks..."
./scripts/tests/ibc-hooks/increment.sh

clean-testing-data:
@echo "Killing terrad and removing previous data"
@echo "Killing migallod and removing previous data"
-@pkill $(BINARY) 2>/dev/null
-@pkill rly 2>/dev/null
-@pkill migalood_new 2>/dev/null
Expand Down
28 changes: 15 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package app
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"sort"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -44,11 +50,6 @@ import (
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
icq "github.com/strangelove-ventures/async-icq/v7"
"io"
"net/http"
"os"
"path/filepath"
"sort"

distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -296,7 +297,7 @@ type MigalooApp struct {

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
TransferStack *ibchooks.IBCMiddleware
TransferStack *ibcporttypes.IBCModule

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -321,7 +322,7 @@ type MigalooApp struct {
}

func (app *MigalooApp) Close() error {
//TODO implement me
// TODO implement me
panic("implement me")
}

Expand Down Expand Up @@ -568,7 +569,7 @@ func NewMigalooApp(
// IBC Fee Module keeper
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, keys[ibcfeetypes.StoreKey],
app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
app.HooksICS4Wrapper, // may be replaced with IBC middleware
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper,
)
Expand Down Expand Up @@ -667,16 +668,16 @@ func NewMigalooApp(
var transferStack ibcporttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
transferStack = ibchooks.NewIBCMiddleware(transferStack, &app.HooksICS4Wrapper)
transferStack = router.NewIBCMiddleware(
transferStack,
&app.RouterKeeper,
0,
5,
routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
// Hooks Middleware
hooksTransferStack := ibchooks.NewIBCMiddleware(transferStack, &app.HooksICS4Wrapper)
app.TransferStack = &hooksTransferStack
app.TransferStack = &transferStack

// Create Interchain Accounts Stack
// SendPacket, since it is originating from the application to core IBC:
Expand Down Expand Up @@ -706,9 +707,10 @@ func NewMigalooApp(

// Create static IBC router, add app routes, then set and seal it
ibcRouter := ibcporttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, *app.TransferStack).
AddRoute(wasmtypes.ModuleName, wasmStack).
AddRoute(icqtypes.ModuleName, icqStack)

app.IBCKeeper.SetRouter(ibcRouter)
Expand Down
108 changes: 108 additions & 0 deletions scripts/tests/alliance/delegate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

echo ""
echo "#################################################"
echo "# Alliance: bridge funds and create an alliance #"
echo "#################################################"
echo ""

BINARY=migalood
CHAIN_DIR=$(pwd)/data

AMOUNT_TO_DELEGATE=10000000000
UWHALE_DENOM=uwhale
VAL_WALLET_1=$($BINARY keys show val1 -a --keyring-backend test --home $CHAIN_DIR/test-1)
VAL_WALLET_2=$($BINARY keys show val2 -a --keyring-backend test --home $CHAIN_DIR/test-2)

echo "Sending tokens from validator wallet on test-1 to validator wallet on test-2"
IBC_TRANSFER=$($BINARY tx ibc-transfer transfer transfer channel-0 $VAL_WALLET_2 $AMOUNT_TO_DELEGATE$UWHALE_DENOM --chain-id test-1 --from $VAL_WALLET_1 --home $CHAIN_DIR/test-1 --fees 60000$UWHALE_DENOM --node tcp://localhost:16657 --keyring-backend test -y -o json | jq -r '.raw_log' )

if [[ "$IBC_TRANSFER" == "failed to execute message"* ]]; then
echo "Error: IBC transfer failed, with error: $IBC_TRANSFER"
exit 1
fi

ACCOUNT_BALANCE=""
IBC_DENOM=""
while [ "$ACCOUNT_BALANCE" == "" ]; do
IBC_DENOM=$($BINARY q bank balances $VAL_WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.balances[0].denom')
IBC_QUERY=$($BINARY q bank balances $VAL_WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json)

echo $IBC_QUERY
if [ "$IBC_DENOM" != "$UWHALE_DENOM" ]; then
ACCOUNT_BALANCE=$($BINARY q bank balances $VAL_WALLET_2 --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.balances[0].amount')
fi
sleep 2
done

GOV_ADDRESS=$($BINARY query auth module-account gov --output json | jq .account.base_account.address -r)
echo '{
"messages": [
{
"@type": "/alliance.alliance.MsgCreateAlliance",
"authority" : "'"$GOV_ADDRESS"'",
"denom": "'"$IBC_DENOM"'",
"reward_weight": "0.3",
"take_rate": "0.01",
"reward_change_rate": "0.01",
"reward_change_interval": "10s",
"reward_weight_range": {
"min":"0.0001",
"max":"0.3"
}
}
],
"metadata": "",
"deposit": "25000000000'$UWHALE_DENOM'",
"title": "Create an Alliance!",
"summary": "Source Code Version https://github.com/terra-money/core"
}' > $CHAIN_DIR/create-alliance.json


echo "Creating an alliance with the denom $IBC_DENOM"
PROPOSAL_HEIGHT=$($BINARY tx gov submit-proposal $CHAIN_DIR/create-alliance.json --from=$VAL_WALLET_2 --home $CHAIN_DIR/test-2 --node tcp://localhost:26657 -o json --keyring-backend test --fees 60000$UWHALE_DENOM -y | jq -r '.height')
sleep 3


PROPOSAL_ID=$($BINARY query gov proposals --home $CHAIN_DIR/test-2 --count-total --node tcp://localhost:26657 -o json --output json --chain-id=test-2 | jq .proposals[-1].id -r)


VOTE_RES=$($BINARY tx gov vote $PROPOSAL_ID yes --from=$VAL_WALLET_2 --home $CHAIN_DIR/test-2 --keyring-backend=test --fees 60000$UWHALE_DENOM --chain-id=test-2 --node tcp://localhost:26657 -o json -y)
echo "Vote res: $VOTE_RES"

ALLIANCE="null"
while [ "$ALLIANCE" == "null" ]; do
echo "Waiting for alliance with denom $IBC_DENOM to be created"
ALLIANCE=$($BINARY q alliance alliances --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.alliances[0]')
ALLIANCE_QUERY=$($BINARY q alliance alliances --chain-id test-2 --node tcp://localhost:26657 -o json)
echo $ALLIANCE_QUERY

sleep 2
done

echo "Delegating $AMOUNT_TO_DELEGATE to the alliance $IBC_DENOM"
VAL_ADDR=$($BINARY query staking validators --output json | jq .validators[0].operator_address --raw-output)
DELEGATE_RES=$($BINARY tx alliance delegate $VAL_ADDR $AMOUNT_TO_DELEGATE$IBC_DENOM --from=node0 --from=$VAL_WALLET_2 --home $CHAIN_DIR/test-2 --keyring-backend=test --fees 60000$UWHALE_DENOM --chain-id=test-2 -o json -y)
sleep 3
DELEGATIONS=$($BINARY query alliance delegation $VAL_WALLET_2 $VAL_ADDR $IBC_DENOM --chain-id test-2 --node tcp://localhost:26657 -o json | jq -r '.delegation.balance.amount')
if [[ "$DELEGATIONS" == "0" ]]; then
echo "Error: Alliance delegations expected to be greater than 0"
exit 1
fi

echo "Query bank balance after alliance creation"
TOTAL_SUPPLY_BEFORE_ALLIANCE=$($BINARY query bank total --denom $UWHALE_DENOM --height $PROPOSAL_HEIGHT -o json | jq -r '.amount')
TOTAL_SUPPLY_AFTER_ALLIANCE=$($BINARY query bank total --denom $UWHALE_DENOM -o json | jq -r '.amount')
TOTAL_SUPPLY_INCREMENT=$(($TOTAL_SUPPLY_BEFORE_ALLIANCE - $TOTAL_SUPPLY_AFTER_ALLIANCE))


if [ "$TOTAL_SUPPLY_INCREMENT" -gt 100000 ] && [ "$TOTAL_SUPPLY_INCREMENT" -lt 1000000 ]; then
echo "Error: Something went wrong, total supply of $UWHALE_DENOM has increased out of range 100_000 between 1_000_000. current value $TOTAL_SUPPLY_INCREMENT"
exit 1
fi

echo ""
echo "#########################################################"
echo "# Success: Alliance bridge funds and create an alliance #"
echo "#########################################################"
echo ""
43 changes: 43 additions & 0 deletions scripts/tests/ibc-hooks/counter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "counter"
description = "Cosmwasm counter dapp, with permissions for testing Osmosis wasmhooks"
version = "0.1.0"
authors = ["osmosis contributors"]
edition = "2021"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.6
"""

[dependencies]
cosmwasm-schema = "1.1.3"
cosmwasm-std = "1.1.3"
cosmwasm-storage = "1.1.3"
cw-storage-plus = "0.16.0"
cw2 = "0.16.0"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }

[dev-dependencies]
cw-multi-test = "0.16.0"
11 changes: 11 additions & 0 deletions scripts/tests/ibc-hooks/counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Counter contract from [Osmosis Labs](https://github.com/osmosis-labs/osmosis/commit/64393a14e18b2562d72a3892eec716197a3716c7)

This contract is a modification of the standard cosmwasm `counter` contract.
Namely, it tracks a counter, _by sender_.
This is a better way to test wasmhooks.

This contract tracks any funds sent to it by adding it to the state under the `sender` key.

This way we can verify that, independently of the sender, the funds will end up under the
`WasmHooksModuleAccount` address when the contract is executed via an IBC send that goes
through the wasmhooks module.
1 change: 1 addition & 0 deletions scripts/tests/ibc-hooks/counter/artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c0e7a3b40d9710f6f72322293ba5cd871714008d9accd9a91c0fb08272609054 counter.wasm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bffb3256d4fd5668e497ae5671844ef3dcdf1a5f2594747b894dfc02e243ab0e ./target/wasm32-unknown-unknown/release/counter.wasm
Binary file not shown.
Loading
Loading