forked from CosmWasm/wasmd
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Feat/orai-osmosis-ict #64
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e86a6fe
feat: init setup ibc orai-osmosis
ledanghuy1811 9e9de08
feat: refactor createChains func
ledanghuy1811 295c3d3
fix: not created chain if not supported
ledanghuy1811 faee58b
feat: add test to force trasnfer token factory after transfer ibc
ledanghuy1811 fa16ebb
feat: remove force transfer capability and add test
ledanghuy1811 2cc1186
feat: solve rebase conflict
ledanghuy1811 e8b6175
feat: update ict test for orai-osmosis ibc
ledanghuy1811 9e22e07
chore: add github action for orai-osmosis ibc test
ledanghuy1811 d271763
chore: rename test force transfer token factory ibc
ledanghuy1811 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,67 @@ | ||
#!/bin/bash | ||
|
||
set -ux | ||
|
||
CHAIN_ID=${CHAIN_ID:-testing} | ||
USER=${USER:-"validator1"} | ||
NODE_HOME=${NODE_HOME:-"$PWD/.oraid"} | ||
ARGS="--from $USER --chain-id $CHAIN_ID -y --keyring-backend test --gas auto --gas-adjustment 1.5 -b sync --home $NODE_HOME" | ||
HIDE_LOGS="/dev/null" | ||
|
||
# prepare a new contract for gasless | ||
fee_params=$(oraid query tokenfactory params --output json | jq '.params.denom_creation_fee[0].denom') | ||
if ! [[ $fee_params =~ "orai" ]]; then | ||
echo "Tokenfactory force transfer tests failed. The tokenfactory fee params is not orai" | ||
exit 1 | ||
fi | ||
|
||
# try creating a new denom | ||
denom_name="usd" | ||
oraid tx tokenfactory create-denom $denom_name $ARGS >$HIDE_LOGS | ||
|
||
# try querying list denoms afterwards | ||
# need to sleep 1s | ||
sleep 1 | ||
user_address=$(oraid keys show $USER --home $NODE_HOME --keyring-backend test -a) | ||
first_denom=$(oraid query tokenfactory denoms-from-creator $user_address --output json | jq '.denoms[0]' | tr -d '"') | ||
echo "first denom: $first_denom" | ||
|
||
if ! [[ $first_denom =~ "factory/$user_address/$denom_name" ]]; then | ||
echo "Tokenfactory force transfer tests failed. The tokenfactory denom does not match the created denom" | ||
exit 1 | ||
fi | ||
|
||
admin=$(oraid query tokenfactory denom-authority-metadata $first_denom --output json | jq '.authority_metadata.admin') | ||
echo "admin: $admin" | ||
|
||
if ! [[ $admin =~ $user_address ]]; then | ||
echo "Tokenfactory force transfer tests failed. The tokenfactory admin does not match the creator" | ||
exit 1 | ||
fi | ||
|
||
sleep 2 | ||
# try to mint token | ||
oraid tx tokenfactory mint 10000$first_denom $ARGS >$HIDE_LOGS | ||
|
||
# query balance after mint | ||
# need sleep 1s | ||
sleep 2 | ||
tokenfactory_balance=$(oraid query bank balance $user_address $first_denom --output json | jq '.balance.amount | tonumber') | ||
if [[ $tokenfactory_balance -ne 10000 ]]; then | ||
echo "Tokenfactory force transfer failed. The tokenfactory balance does not increase after mint" | ||
exit 1 | ||
fi | ||
|
||
# try to force transfer token to another address | ||
oraid tx tokenfactory force-transfer 10$first_denom $user_address orai1cknd27x0244595pp7a5c9sdekl3ywl52x62ssn $ARGS &>$HIDE_LOGS | ||
|
||
# query balance after force trasnfer | ||
# need sleep 2s | ||
sleep 2 | ||
tokenfactory_balance=$(oraid query bank balance $user_address $first_denom --output json | jq '.balance.amount | tonumber') | ||
if ! [[ $tokenfactory_balance =~ 10000 ]]; then | ||
echo "Tokenfactory force transfer failed. The tokenfactory balance decreases after force transfer" | ||
exit 1 | ||
fi | ||
|
||
echo "Tokenfactory force transfer tests passed!" |
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
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
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
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
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,130 @@ | ||
package interchaintest | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
"github.com/oraichain/wasmd/tests/interchaintest/helpers" | ||
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v8/ibc" | ||
"github.com/strangelove-ventures/interchaintest/v8/testutil" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestStartOrai is a basic test to assert that spinning up a Orai network with 1 validator works properly. | ||
func TestOraiOsmoIbc(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip() | ||
} | ||
|
||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
chains := CreateChains(t, 1, 1, []string{"orai", "osmosis"}) | ||
orai, osmo := chains[0].(*cosmos.CosmosChain), chains[1].(*cosmos.CosmosChain) | ||
|
||
// Create relayer factory to utilize the go-relayer | ||
ic, r, ctx, _, eRep, _ := BuildInitialChain(t, chains, pathOraiOsmo) | ||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
|
||
// Start the relayer | ||
require.NoError(t, r.StartRelayer(ctx, eRep, pathOraiOsmo)) | ||
t.Cleanup( | ||
func() { | ||
err := r.StopRelayer(ctx, eRep) | ||
if err != nil { | ||
panic(fmt.Errorf("an error occurred while stopping the relayer: %s", err)) | ||
} | ||
}, | ||
) | ||
|
||
channel, err := ibc.GetTransferChannel(ctx, r, eRep, orai.Config().ChainID, osmo.Config().ChainID) | ||
require.NoError(t, err) | ||
|
||
users := CreateTestingUser(t, ctx, t.Name(), genesisWalletAmount, chains...) | ||
// Get our Bech32 encoded user addresses | ||
oraiUser, osmoUser := users[0], users[1] | ||
|
||
oraiUserAddress := sdk.MustBech32ifyAddressBytes(orai.Config().Bech32Prefix, oraiUser.Address()) | ||
osmoUserAddr := sdk.MustBech32ifyAddressBytes(osmo.Config().Bech32Prefix, osmoUser.Address()) | ||
|
||
_ = oraiUserAddress | ||
_ = osmoUserAddr | ||
gas := uint64(100_000_000) | ||
|
||
// create new token factory denom | ||
expectedDenom, _ := helpers.TxTokenFactoryCreateDenom(t, ctx, orai, oraiUser, "orai-usd", gas) | ||
denomCreated, err := helpers.QueryDenomsFromCreator(t, ctx, orai, oraiUserAddress) | ||
require.NoError(t, err) | ||
require.Contains(t, denomCreated, expectedDenom) | ||
|
||
// mint token | ||
tokenToMint := uint64(100_000_000_000) | ||
_ = helpers.TxTokenFactoryMintToken(t, ctx, orai, oraiUser, expectedDenom, tokenToMint) | ||
oraiUserBalance, err := helpers.QueryBalance(t, ctx, orai, expectedDenom, oraiUserAddress) | ||
require.NoError(t, err) | ||
require.Equal(t, tokenToMint, oraiUserBalance) | ||
|
||
// get escrowed address | ||
addr := types.GetEscrowAddress(channel.PortID, channel.ChannelID) | ||
escrowedAddress := sdk.MustBech32ifyAddressBytes(orai.Config().Bech32Prefix, addr.Bytes()) | ||
|
||
// balance before transfer ibc must be 0 | ||
escrowedBalance, err := helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress) | ||
require.NoError(t, err) | ||
require.Equal(t, escrowedBalance, uint64(0)) | ||
|
||
// ibc denom when transfer orai to osmosis | ||
// transfer/channel-0/factory/orai14zqwen0pqj7s6drrkwaqwded7ajrq5czyw7fhq/orai-usd | ||
oraiDenom := transfertypes.GetPrefixedDenom(channel.Counterparty.PortID, channel.Counterparty.ChannelID, expectedDenom) | ||
// ibc/F859A4CC5A5EA6533657F6A83F7C11A479A13DBDC53F68135CDA95B0F12E5892 | ||
oraiIBCDenom := transfertypes.ParseDenomTrace(oraiDenom).IBCDenom() | ||
|
||
// osmosis user balance before transfer ibc must be 0 | ||
userOsmosisBalance, err := helpers.QueryBalance(t, ctx, osmo, oraiIBCDenom, osmoUserAddr) | ||
require.NoError(t, err) | ||
require.Equal(t, userOsmosisBalance, uint64(0)) | ||
|
||
// try to transfer token factory to osmosis | ||
transfer := ibc.WalletAmount{ | ||
Address: osmoUserAddr, | ||
Denom: expectedDenom, | ||
Amount: amountToSend, | ||
} | ||
transferTx, err := orai.SendIBCTransfer(ctx, channel.Counterparty.ChannelID, oraiUserAddress, transfer, ibc.TransferOptions{}) | ||
require.NoError(t, err) | ||
|
||
// waiting for ACK -> transfer successfully | ||
oraiHeight, err := orai.Height(ctx) | ||
require.NoError(t, err) | ||
_, err = testutil.PollForAck(ctx, orai, oraiHeight-5, oraiHeight+25, transferTx.Packet) | ||
require.NoError(t, err) | ||
|
||
// balance after transfer ibc must be equalt amount to send | ||
escrowedBalance, err = helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress) | ||
fmt.Println("escrowed balance: ", escrowedBalance) | ||
require.NoError(t, err) | ||
require.Equal(t, escrowedBalance, uint64(amountToSend.Int64())) | ||
|
||
// osmosis user balance after transfer ibc must be equal amount to send | ||
userOsmosisBalance, err = helpers.QueryBalance(t, ctx, osmo, oraiIBCDenom, osmoUserAddr) | ||
require.NoError(t, err) | ||
require.Equal(t, userOsmosisBalance, uint64(amountToSend.Int64())) | ||
|
||
// try to force transfer tokenfactory from escrowed address | ||
_, err = helpers.TxTokenFactoryForceTransfer(t, ctx, orai, oraiUser, expectedDenom, uint64(amountToSend.Int64()), escrowedAddress, oraiUserAddress) | ||
require.Error(t, err) | ||
|
||
escrowedBalance, err = helpers.QueryBalance(t, ctx, orai, expectedDenom, escrowedAddress) | ||
fmt.Println("escrowed balance: ", escrowedBalance) | ||
require.NoError(t, err) | ||
require.Equal(t, escrowedBalance, uint64(amountToSend.Int64())) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name this something like TestTokenfactoryForceTransfer ...