-
Notifications
You must be signed in to change notification settings - Fork 172
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
ab03d6c
commit 1477880
Showing
5 changed files
with
165 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package helpers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v7/ibc" | ||
"github.com/strangelove-ventures/interchaintest/v7/testutil" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
) | ||
|
||
func RegisterFeePay(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contract string, walletLimit uint) { | ||
cmd := []string{ | ||
"junod", "tx", "feepay", "register", contract, fmt.Sprintf("%d", walletLimit), | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--fees", "500ujuno", | ||
"--from", user.KeyName(), | ||
"--keyring-dir", chain.HomeDir(), | ||
"--keyring-backend", keyring.BackendTest, | ||
"-y", | ||
} | ||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
debugOutput(t, string(stdout)) | ||
|
||
err = testutil.WaitForBlocks(ctx, 2, chain) | ||
require.NoError(t, err) | ||
} | ||
|
||
func FundFeePayContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contract string, amountCoin string) { | ||
cmd := []string{ | ||
"junod", "tx", "feepay", "fund", contract, amountCoin, | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--fees", "500ujuno", | ||
"--from", user.KeyName(), | ||
"--keyring-dir", chain.HomeDir(), | ||
"--keyring-backend", keyring.BackendTest, | ||
"-y", | ||
} | ||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
debugOutput(t, string(stdout)) | ||
|
||
err = testutil.WaitForBlocks(ctx, 2, chain) | ||
require.NoError(t, err) | ||
} | ||
|
||
func UpdateFeePayWalletLimit(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, contract string, newLimit uint64) { | ||
cmd := []string{ | ||
"junod", "tx", "feepay", "update-wallet-limit", contract, fmt.Sprintf("%d", newLimit), | ||
"--node", chain.GetRPCAddress(), | ||
"--home", chain.HomeDir(), | ||
"--chain-id", chain.Config().ChainID, | ||
"--from", user.KeyName(), | ||
"--keyring-dir", chain.HomeDir(), | ||
"--keyring-backend", keyring.BackendTest, | ||
"-y", | ||
} | ||
stdout, _, err := chain.Exec(ctx, cmd, nil) | ||
require.NoError(t, err) | ||
|
||
debugOutput(t, string(stdout)) | ||
|
||
err = testutil.WaitForBlocks(ctx, 2, chain) | ||
require.NoError(t, err) | ||
} | ||
|
||
// TODO: | ||
// {"fee_pay_contract":{"contract_address":"juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8","balance":"1000000","wallet_limit":"5"}} | ||
// feepay contract juno14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9skjuwg8 |
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,79 @@ | ||
package interchaintest | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/strangelove-ventures/interchaintest/v7" | ||
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v7/testutil" | ||
|
||
helpers "github.com/CosmosContracts/juno/tests/interchaintest/helpers" | ||
) | ||
|
||
// TestJunoFeePay | ||
func TestJunoFeePay(t *testing.T) { | ||
t.Parallel() | ||
|
||
cfg := junoConfig | ||
cfg.GasPrices = "0.0025ujuno" | ||
|
||
// Base setup | ||
chains := CreateChainWithCustomConfig(t, 1, 0, cfg) | ||
ic, ctx, _, _ := BuildInitialChain(t, chains) | ||
|
||
// Chains | ||
juno := chains[0].(*cosmos.CosmosChain) | ||
|
||
nativeDenom := juno.Config().Denom | ||
|
||
// Users | ||
users := interchaintest.GetAndFundTestUsers(t, ctx, "default", int64(10_000_000), juno, juno) | ||
admin := users[0] | ||
user := users[1] | ||
|
||
// Upload & init contract payment to another address | ||
codeId, err := juno.StoreContract(ctx, admin.KeyName(), "contracts/cw_template.wasm", "--fees", "50000ujuno") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
contractAddr, err := juno.InstantiateContract(ctx, admin.KeyName(), codeId, `{"count":0}`, true) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Register contract for 0 fee usage (x amount of times) | ||
helpers.RegisterFeePay(t, ctx, juno, admin, contractAddr, 5) | ||
helpers.FundFeePayContract(t, ctx, juno, admin, contractAddr, "1000000"+nativeDenom) | ||
|
||
// execute against it from another account with enough fees (standard Tx) | ||
txHash, err := juno.ExecuteContract(ctx, user.KeyName(), contractAddr, `{"increment":{}}`, "--fees", "500"+nativeDenom) | ||
if err != nil { | ||
// TODO: | ||
t.Log(err) | ||
} | ||
fmt.Println("txHash", txHash) | ||
|
||
// execute against it from another account and have the dev pay it | ||
txHash, err = juno.ExecuteContract(ctx, user.KeyName(), contractAddr, `{"increment":{}}`, "--fees", "0"+nativeDenom) | ||
if err != nil { | ||
// TODO: | ||
t.Log(err) | ||
} | ||
fmt.Println("txHash", txHash) | ||
|
||
// validate their balance did not go down, and that the contract did infact increase +=1 | ||
// if balance, err := juno.GetBalance(ctx, feeRcvAddr, nativeDenom); err != nil { | ||
// t.Fatal(err) | ||
// } else if balance != 0 { | ||
// t.Fatal("balance not 0") | ||
// } | ||
|
||
// wait blocks | ||
testutil.WaitForBlocks(ctx, 200, juno) | ||
|
||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
} |
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