• Nicolas Lara's avatar
    Rate limit - Cleaner tests (#3183) · bb5c1c99
    Nicolas Lara authored
    * improved testing framework
    
    * can test both send and recv for success and failure
    
    * cleanner testing framework
    
    * added contract instantiation
    
    * working wasm integration
    
    * added params for contract config
    
    * extracted param registration
    
    * active rate limiting
    
    * calculating channel value
    
    * cleaner tests
    
    * fix issue with epochs
    
    * fixed tests
    
    * testing rate limit reset
    
    * linting
    
    * added receive middleware
    
    * added test for non-configured channel
    
    * make format
    
    * Revert "make format"
    
    This reverts commit 9ffdc37c.
    
    * only applying format to ibc-rate-limit
    
    * applying fmt to app.go
    
    * added gov_module and changed no-quota default to "allow all"
    
    * added asymetric quotas
    
    * moved getters to modules.go
    
    * initial work to support multiple quotas
    
    * added multiple quotas
    
    * small fixes
    
    * reordered imports
    
    * added management messages
    
    * reorganized management messages and experimenting with e2e testing
    
    * commenting out test configuration test for now
    
    * added query
    
    * added flow unit test
    
    * cleanup
    
    * added AddChannel tests
    
    * format
    
    * test values are properly stored
    
    * testing remove channel
    
    * some more rate limiting tests
    
    * moved tests about test setup to the right place
    
    * fixed params
    
    * merged main
    
    * running gofumpt
    
    * added ibc-rate-limiting contract
    
    * added ibc-rate-limit middleware
    
    * added chain integration and tests
    
    * reverted change to match merged branch in main (#2341 instead of #2274)
    
    * added cosmwasm workflow
    
    * added a migrate message
    
    * added some doc comments to the state
    
    * added doc comments
    
    * fixed dependency after merging https://github.com/osmosis-labs/cosmos-sdk/pull/312
    
    
    
    * added migration msg
    
    * added workflow
    
    * experimenting with better workflow
    
    * added missing $
    
    * using env
    
    * Update x/ibc-rate-limit/contracts/rate-limiter/src/msg.rs
    
    Co-authored-by: default avatarDev Ojha <ValarDragon@users.noreply.github.com>
    
    * using stable for clippy
    
    * removed gitkeep
    
    * using the minimal profile for clippy
    
    * experimenting with cache
    
    * removed target from lints
    
    * cleaner matrix?
    
    * COmments & questions
    
    * debugging
    
    * more debugging
    
    * debug faster
    
    * quick cache debug
    
    * typo
    
    * quick workflow check
    
    * working tests with optimization
    
    * testing artifacts
    
    * split the wasm target into its own step
    
    * artifacts without slash
    
    * full working tests
    
    * clippy fixes
    
    * workflow without test data checks and clippy fixes
    
    * renamed CHANNEL_FLOWS
    
    * renaming and code clenaup
    
    * more renames
    
    * renames and code fixes
    
    * reordered imports
    
    * cargo fmt
    
    * added danom tracking
    
    * cleanup
    
    * refactoring
    
    * changes to the expiration logic so that balances are calculated based on the direction (as suggested by @ValarDragon)
    
    * slightly slower but considerably cleanner
    
    * cleanup attributes and removed redundancy when not testing
    
    * update to edition 2021
    
    * added comments explaining the tests
    
    * removed .beaker
    
    * unified gitignore
    
    * removed second gitignore
    
    * better doc comments
    
    * spelling
    
    * spelling
    
    * added channel value cache
    
    * updated the middlware to use the new contract interface
    
    * update middleware to match new contract interface
    
    * added missing updates
    
    * updated dependencies
    
    * added missing helpers
    
    * go.mod changes shouldn't be in this branch
    
    * Revert "go.mod changes shouldn't be in this branch"
    
    This reverts commit f8b972a5
    
    .
    
    * moved send and receive to sudo
    
    * reorganizing
    
    * calling the contract via sudo
    
    * lint
    
    * removed gitkeep
    
    * using sudo instead of execute
    
    * cleaned up and updated contract and integration
    
    * updated x86 test wasm file
    
    * fixed bad print
    
    * storing and instantiating the contract
    
    * setting up E2E tests for ibc rate limits
    
    * fixed proposal. Now just have to get the math right and cleanup
    
    * Using the supply for the channel value
    
    * experimenting with e2e tests
    
    * passing the contract keeper instead of instantiating it each time
    
    * changes from code review
    
    * added contract from main and changes to the middleware from code review
    
    * using the correct bank supply method
    
    * debugging issues with e2e tests. Everything works after one interaction from the cli, but not before
    
    * updated dependency to match latest sdk form (now that the changes to this repo have been applied)
    
    * working E2E test for rate limiting
    
    * added e2e tests and changes from code review
    
    * removed debug logs
    
    * remove debug logs
    
    * updated test to also use GetSupplyWithOffset
    
    * using correct GetSupplyWithOffset method
    
    * using correct GetSupplyWithOffset method
    
    * lint
    
    * removed e2e from this branch as it's not doing anything without the integration
    
    * lint
    
    * tests fail on CI because of "inactive" proposal. Is the deposit the issue?
    
    * remove rate limiting after the test so it doesn't interfeer with the other tests
    
    * using standard proposals instead of expedited
    
    * added packet reverts on unsuccessful acks and timeouts
    
    * lint
    
    * ran gofumpt
    
    * lint
    
    * added undo to the contract
    
    * integrating undo
    
    * updated contract with x86 wasm file
    
    * added undo for sent packages when they are rejected bia timeout or a bad ack
    
    * added a readme
    
    * markdown lint
    
    * added readme
    
    * abstracted params
    
    * better params and param tests
    
    * using a helper function instead of returning from the test
    
    * updated contract to allow for undo
    
    * added undo, readme, and cleanup based on reviews
    
    * updated wasm file with x86 version
    
    * using string params in e2e tests
    
    * updated to v12
    
    * removed unnecessary keeper
    
    * only exposing what's needed
    
    * refactoring
    
    * updated types
    
    * added shell history to gitignore
    
    * adding only one wasm file to the codebase
    
    * remove test for same wasm files. No longer needed.
    
    * refactor based on code review
    
    * removed integration tests as they won't pass without integration
    
    * added params unit test
    
    * reorganized tests
    
    * reorganizing tests
    
    * refactoring
    
    * added address length limit
    
    * added tests and fixed lack of return
    
    * remove tests from bad merge
    
    * remove from bad merge again
    
    * comment
    
    * test helpers for cosmwasm contracts
    
    * added helpers for ibctesting
    
    * comments
    
    * removed unnecessary txConfig
    
    * fixed typos
    
    * clearer comment
    
    * using second helper function for ExportGenesis
    
    * added new wasm file
    
    * updated the contract to cosmwasm 1.1 and Uint256 for amounts
    
    * Fixed send with ibc assets. Better tests and error messages
    
    * updated contract with x86 version
    
    * gofumpt
    
    * fixed clippy errors
    
    * using the escrowed value as the channel value for native tokens
    
    * gofumpt
    
    * update fail string
    
    * initial experiments with moving the calculations into the contract
    
    * initial experiments with using the packet inside the contract
    
    * improved tests. Experiments with packet in the contract.
    
    * original contract
    
    * cleaner tests
    
    * more test cleanup
    
    * cleaner tests
    
    * cleanup
    
    * align values from the tests and the contract
    
    * fixed amounts for receive and cleanup code
    
    * removed redundant wrapping logic
    
    * adaped failed send test to the new testing abstractions
    
    * only manipulate time on chain A
    
    * remove commented out block
    
    * changed lints to stable so they change less often
    
    * gofumpt
    
    * update channel value tests
    
    * added x86 version of the contract for ci
    
    * remove lint type that doesn't exist on stable
    
    Co-authored-by: default avatarDev Ojha <ValarDragon@users.noreply.github.com>
    Co-authored-by: default avatarDev Ojha <dojha@berkeley.edu>
    bb5c1c99
wasm.go 2.44 KiB
package osmosisibctesting
import (
	"fmt"
	"io/ioutil"
	"github.com/stretchr/testify/require"
	wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
	wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
	sdk "github.com/cosmos/cosmos-sdk/types"
	govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
	transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
	"github.com/osmosis-labs/osmosis/v12/x/ibc-rate-limit/types"
	"github.com/stretchr/testify/suite"
func (chain *TestChain) StoreContractCode(suite *suite.Suite) {
	osmosisApp := chain.GetOsmosisApp()
	govKeeper := osmosisApp.GovKeeper
	wasmCode, err := ioutil.ReadFile("./testdata/rate_limiter.wasm")
	suite.Require().NoError(err)
	addr := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
	src := wasmtypes.StoreCodeProposalFixture(func(p *wasmtypes.StoreCodeProposal) {
		p.RunAs = addr.String()
		p.WASMByteCode = wasmCode
	// when stored
	storedProposal, err := govKeeper.SubmitProposal(chain.GetContext(), src, false)
	suite.Require().NoError(err)
	// and proposal execute
	handler := govKeeper.Router().GetRoute(storedProposal.ProposalRoute())
	err = handler(chain.GetContext(), storedProposal.GetContent())
	suite.Require().NoError(err)
func (chain *TestChain) InstantiateContract(suite *suite.Suite, quotas string) sdk.AccAddress {
	osmosisApp := chain.GetOsmosisApp()
	transferModule := osmosisApp.AccountKeeper.GetModuleAddress(transfertypes.ModuleName)
	govModule := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
	initMsgBz := []byte(fmt.Sprintf(`{
           "gov_module":  "%s",
           "ibc_module":"%s",
           "paths": [%s]
        }`,
		govModule, transferModule, quotas))
	contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(osmosisApp.WasmKeeper)
	codeID := uint64(1)
	creator := osmosisApp.AccountKeeper.GetModuleAddress(govtypes.ModuleName)
	addr, _, err := contractKeeper.Instantiate(chain.GetContext(), codeID, creator, creator, initMsgBz, "rate limiting contract", nil)
	suite.Require().NoError(err)
	return addr
func (chain *TestChain) RegisterRateLimitingContract(addr []byte) {
	addrStr, err := sdk.Bech32ifyAddressBytes("osmo", addr)
	require.NoError(chain.T, err)
	params, err := types.NewParams(addrStr)
	require.NoError(chain.T, err)
	osmosisApp := chain.GetOsmosisApp()
	paramSpace, ok := osmosisApp.AppKeepers.ParamsKeeper.GetSubspace(types.ModuleName)
	require.True(chain.T, ok)
	paramSpace.SetParamSet(chain.GetContext(), &params)
71