diff --git a/.github/workflows/buildtest.yaml b/.github/workflows/buildtest.yaml index 31eb53ece..f969c3b52 100644 --- a/.github/workflows/buildtest.yaml +++ b/.github/workflows/buildtest.yaml @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" env: GOOS: ${{ matrix.targetos }} GOARCH: ${{ matrix.arch }} @@ -63,7 +63,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" env: GOOS: ${{ matrix.targetos }} GOARCH: ${{ matrix.arch }} @@ -93,10 +93,10 @@ jobs: filename=$(echo $filename | sed 's/^./github.com\/ingenuity-build\/quicksilver/g') echo "Excluding ${filename} from coverage report..." sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt - done + done - name: "Go vulnerability checks" - continue-on-error: false #temp-till we upgrade to v1.20 + continue-on-error: false #temp-till we upgrade to v1.20 run: make vulncheck - name: Upload coverage reports to Codecov with GitHub Action @@ -124,6 +124,6 @@ jobs: ${{ runner.os }}-go- - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - name: Run simulation tests run: make test-sim-ci diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index c3d95b01a..d4b2b2bb0 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -3,13 +3,12 @@ name: Docker on: push: branches: - - 'develop' + - "develop" jobs: docker: runs-on: ubuntu-latest steps: - - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -25,7 +24,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - name: Setup Golang caches uses: actions/cache@v3 @@ -40,4 +39,4 @@ jobs: - name: build and push container run: | DOCKER_BUILDKIT=1 /usr/bin/docker build . -f Dockerfile -t quicksilverzone/quicksilver:latest - /usr/bin/docker push quicksilverzone/quicksilver:latest + /usr/bin/docker push quicksilverzone/quicksilver:latest diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index d2d44f57a..66c55b3c0 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/interchaintest.yaml b/.github/workflows/interchaintest.yaml index 32fc10388..8bb4b31a8 100644 --- a/.github/workflows/interchaintest.yaml +++ b/.github/workflows/interchaintest.yaml @@ -3,13 +3,13 @@ name: create docker image + E2E Tests on: push: tags: - - '**' + - "**" branches: - - 'main' - - 'develop' + - "main" + - "develop" paths: - - '**.go' - - 'go.sum' + - "**.go" + - "go.sum" env: REGISTRY: quicksilverzone @@ -23,7 +23,6 @@ jobs: build-and-push-image: runs-on: ubuntu-latest steps: - - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -39,10 +38,9 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - - - name: Build and push + - name: Build and push id: build_push_image uses: docker/build-push-action@v3 with: @@ -60,7 +58,7 @@ jobs: - name: Set up Go 1.20 uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" id: go - name: checkout chain @@ -77,7 +75,7 @@ jobs: - name: Set up Go 1.20 uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" id: go - name: checkout chain @@ -94,7 +92,7 @@ jobs: - name: Set up Go 1.20 uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" id: go - name: checkout chain diff --git a/.github/workflows/simulation.yml b/.github/workflows/simulation.yml index b00becf5b..de9f6a0b7 100644 --- a/.github/workflows/simulation.yml +++ b/.github/workflows/simulation.yml @@ -2,7 +2,7 @@ name: simulate quicksilver on: schedule: - - cron: '0 0 * * 0' # run once a week + - cron: "0 0 * * 0" # run once a week jobs: simulate: @@ -19,7 +19,7 @@ jobs: ${{ runner.os }}-go- - uses: actions/setup-go@v4 with: - go-version: '1.20.4' + go-version: "1.20.5" - name: Run simulation tests run: make test-sim-non-determinism diff --git a/Dockerfile.hermes b/Dockerfile.hermes index ac5e9ad97..b618f01ae 100644 --- a/Dockerfile.hermes +++ b/Dockerfile.hermes @@ -4,7 +4,7 @@ RUN apt update && apt install git -y WORKDIR /app/src -RUN git clone https://github.com/informalsystems/ibc-rs --branch v1.4.0 +RUN git clone https://github.com/informalsystems/ibc-rs --branch v1.5.0 WORKDIR ibc-rs diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 7996c21ed..2e7d40f65 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -24,6 +24,7 @@ const ( V010402rc5UpgradeName = "v1.4.2-rc5" V010402rc6UpgradeName = "v1.4.2-rc6" V010402rc7UpgradeName = "v1.4.2-rc7" + V010403rc0UpgradeName = "v1.4.3-rc0" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal diff --git a/app/upgrades/upgrades.go b/app/upgrades/upgrades.go index b9c537210..6cf15ee73 100644 --- a/app/upgrades/upgrades.go +++ b/app/upgrades/upgrades.go @@ -11,7 +11,7 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/ingenuity-build/quicksilver/app/keepers" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -25,6 +25,7 @@ func Upgrades() []Upgrade { {UpgradeName: V010402rc5UpgradeName, CreateUpgradeHandler: V010402rc5UpgradeHandler}, {UpgradeName: V010402rc6UpgradeName, CreateUpgradeHandler: V010402rc6UpgradeHandler}, {UpgradeName: V010402rc7UpgradeName, CreateUpgradeHandler: NoOpHandler}, + {UpgradeName: V010403rc0UpgradeName, CreateUpgradeHandler: V010403rc0UpgradeHandler}, } } @@ -86,10 +87,10 @@ func V010402rc3UpgradeHandler( panic("connection protocol data type not found") } - appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "rege-redwood-1"))) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rege-redwood-1"))) vals := appKeepers.InterchainstakingKeeper.GetValidators(ctx, OsmosisTestnetChainID) for _, val := range vals { - valoper, _ := utils.ValAddressFromBech32(val.ValoperAddress, "osmovaloper") + valoper, _ := addressutils.ValAddressFromBech32(val.ValoperAddress, "osmovaloper") appKeepers.InterchainstakingKeeper.DeleteValidator(ctx, OsmosisTestnetChainID, valoper) } } @@ -109,8 +110,8 @@ func V010402rc4UpgradeHandler( if !exists { panic("liquid tokens protocol data type not found") } - appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "osmo-test-5/ibc/FBD3AC18A981B89F60F9FE5B21BD7F1DE87A53C3505D5A5E438E2399409CFB6F"))) - appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "rhye-1/uqosmo"))) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("osmo-test-5/ibc/FBD3AC18A981B89F60F9FE5B21BD7F1DE87A53C3505D5A5E438E2399409CFB6F"))) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rhye-1/uqosmo"))) rcptTime := time.Unix(1682932342, 0) rcpt1 := types.Receipt{ ChainId: "theta-testnet-001", @@ -250,6 +251,30 @@ func V010402rc6UpgradeHandler( } } +func V010403rc0UpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + appKeepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + if isTestnet(ctx) || isTest(ctx) { + appKeepers.ParticipationRewardsKeeper.IteratePrefixedProtocolDatas(ctx, prtypes.GetPrefixProtocolDataKey(prtypes.ProtocolDataTypeLiquidToken), func(index int64, key []byte, data prtypes.ProtocolData) (stop bool) { + prefixedKey := append(prtypes.GetPrefixProtocolDataKey(prtypes.ProtocolDataTypeLiquidToken), key...) + appKeepers.ParticipationRewardsKeeper.DeleteProtocolData(ctx, prefixedKey) + pd, err := prtypes.UnmarshalProtocolData(prtypes.ProtocolDataTypeLiquidToken, data.Data) + if err != nil { + panic(err) + } + newKey := pd.GenerateKey() + appKeepers.ParticipationRewardsKeeper.SetProtocolData(ctx, newKey, &data) + return false + }) + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} + // func V010400UpgradeHandler( // mm *module.Manager, // configurator module.Configurator, diff --git a/app/upgrades_test.go b/app/upgrades_test.go index b0ecaceb3..98f5c9242 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/ingenuity-build/quicksilver/app/upgrades" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" prtypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" @@ -126,7 +126,7 @@ func (s *AppTestSuite) initTestZone() { receipt := icstypes.Receipt{ ChainId: "uni-5", - Sender: utils.GenerateAccAddressForTest().String(), + Sender: addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix), Txhash: "TestDeposit01", Amount: sdk.NewCoins( sdk.NewCoin( @@ -178,7 +178,7 @@ func (s *AppTestSuite) initTestZone() { wRecord := icstypes.WithdrawalRecord{ ChainId: "uni-5", - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Distribution: []*icstypes.Distribution{ {Valoper: "junovaloper185hgkqs8q8ysnc8cvkgd8j2knnq2m0ah6ae73gntv9ampgwpmrxqlfzywn", Amount: 1000000}, {Valoper: "junovaloper1z89utvygweg5l56fsk8ak7t6hh88fd0aa9ywed", Amount: 1000000}, @@ -195,14 +195,8 @@ func (s *AppTestSuite) initTestZone() { if err != nil { return } - addr1, err := utils.AccAddressFromBech32("quick17v9kk34km3w6hdjs2sn5s5qjdu2zrm0m3rgtmq", "quick") - if err != nil { - return - } - addr2, err := utils.AccAddressFromBech32("quick16x03wcp37kx5e8ehckjxvwcgk9j0cqnhcccnty", "quick") - if err != nil { - return - } + addr1 := addressutils.GenerateAccAddressForTest() + addr2 := addressutils.GenerateAccAddressForTest() err = s.GetQuicksilverApp(s.chainA).BankKeeper.SendCoinsFromModuleToAccount(s.chainA.GetContext(), tokenfactorytypes.ModuleName, addr1, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(1600000)))) if err != nil { @@ -278,22 +272,22 @@ func (s *AppTestSuite) TestV010402rc1UpgradeHandler() { app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { if zone.ChainId == "uni-5" { s.Require().Nil(zone.Validators) - valAddrBytes, err := utils.ValAddressFromBech32("junovaloper185hgkqs8q8ysnc8cvkgd8j2knnq2m0ah6ae73gntv9ampgwpmrxqlfzywn", "junovaloper") + valAddrBytes, err := addressutils.ValAddressFromBech32("junovaloper185hgkqs8q8ysnc8cvkgd8j2knnq2m0ah6ae73gntv9ampgwpmrxqlfzywn", "junovaloper") s.Require().NoError(err) _, found := app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) s.Require().True(found) - valAddrBytes2, err := utils.ValAddressFromBech32("junovaloper1z89utvygweg5l56fsk8ak7t6hh88fd0aa9ywed", "junovaloper") + valAddrBytes2, err := addressutils.ValAddressFromBech32("junovaloper1z89utvygweg5l56fsk8ak7t6hh88fd0aa9ywed", "junovaloper") s.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes2) s.Require().True(found) } if zone.ChainId == "osmosis-1" { s.Require().Nil(zone.Validators) - valAddrBytes, err := utils.ValAddressFromBech32("osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", "osmovaloper") + valAddrBytes, err := addressutils.ValAddressFromBech32("osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", "osmovaloper") s.Require().NoError(err) _, found := app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) s.Require().True(found) - valAddrBytes2, err := utils.ValAddressFromBech32("osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper") + valAddrBytes2, err := addressutils.ValAddressFromBech32("osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", "osmovaloper") s.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes2) s.Require().True(found) @@ -316,7 +310,7 @@ func (s *AppTestSuite) TestV010402rc3UpgradeHandler() { Data: []byte(`{"ConnectionID":"connection-2","ChainID":"regen-redwood-1","Prefix":"regen"}`), } - app.ParticipationRewardsKeeper.SetProtocolData(ctx, string(prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), "rege-redwood-1")), &prData) + app.ParticipationRewardsKeeper.SetProtocolData(ctx, prtypes.GetProtocolDataKey(prtypes.ProtocolDataType(pdType), []byte("rege-redwood-1")), &prData) val0 := icstypes.Validator{ValoperAddress: "osmovaloper1zxavllftfx3a3y5ldfyze7jnu5uyuktsfx2jcc", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} app.InterchainstakingKeeper.SetValidator(ctx, upgrades.OsmosisTestnetChainID, val0) val1 := icstypes.Validator{ValoperAddress: "osmovaloper13eq5c99ym05jn02e78l8cac2fagzgdhh4294zk", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} diff --git a/docker-compose.yml b/docker-compose.yml index 0c8db975e..ae22d142a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -98,7 +98,7 @@ services: - osmosisd - start hermes: - image: quicksilverzone/hermes:v1.4.0 + image: quicksilverzone/hermes:v1.5.0 hostname: hermes volumes: - ./data/hermes:/hermes/.hermes @@ -110,7 +110,7 @@ services: context: . dockerfile: Dockerfile.hermes icq: - image: quicksilverzone/interchain-queries:v0.8.7 + image: quicksilverzone/interchain-queries:v0.9.1 volumes: - ./data/icq:/icq/.icq command: @@ -118,7 +118,7 @@ services: - run restart: always icq2: - image: quicksilverzone/interchain-queries:v0.6.2 + image: quicksilverzone/interchain-queries:v0.9.1 volumes: - ./data/icq2:/icq/.icq command: @@ -126,7 +126,7 @@ services: - run restart: always relayer: - image: quicksilverzone/relayer:v2.1.1 + image: quicksilverzone/relayer:v2.3.0 build: context: . dockerfile: Dockerfile.relayer diff --git a/docs/swagger.yml b/docs/swagger.yml index bdf552730..32d1f848e 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -1688,12 +1688,8 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } - // or ... - if (any.isSameTypeAs(Foo.getDefaultInstance())) { - foo = any.unpack(Foo.getDefaultInstance()); - } - Example 3: Pack and unpack a message in Python. + Example 3: Pack and unpack a message in Python. foo = Foo(...) any = Any() @@ -1703,7 +1699,7 @@ paths: any.Unpack(foo) ... - Example 4: Pack and unpack a message in Go + Example 4: Pack and unpack a message in Go foo := &pb.Foo{...} any, err := anypb.New(foo) @@ -1731,8 +1727,10 @@ paths: name "y.z". + JSON + ==== The JSON representation of an `Any` value uses the regular @@ -2001,12 +1999,8 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } - // or ... - if (any.isSameTypeAs(Foo.getDefaultInstance())) { - foo = any.unpack(Foo.getDefaultInstance()); - } - Example 3: Pack and unpack a message in Python. + Example 3: Pack and unpack a message in Python. foo = Foo(...) any = Any() @@ -2016,7 +2010,7 @@ paths: any.Unpack(foo) ... - Example 4: Pack and unpack a message in Go + Example 4: Pack and unpack a message in Go foo := &pb.Foo{...} any, err := anypb.New(foo) @@ -2044,8 +2038,10 @@ paths: name "y.z". + JSON + ==== The JSON representation of an `Any` value uses the regular diff --git a/osmosis-types/gamm/pool-models/balancer/marshal.go b/osmosis-types/gamm/pool-models/balancer/marshal.go index 4f99c68f4..c00dff48b 100644 --- a/osmosis-types/gamm/pool-models/balancer/marshal.go +++ b/osmosis-types/gamm/pool-models/balancer/marshal.go @@ -2,69 +2,18 @@ package balancer import ( "encoding/json" - "errors" - "strings" - - sdk "github.com/cosmos/cosmos-sdk/types" ) -type balancerPoolPretty struct { - Address sdk.AccAddress `json:"address" yaml:"address"` - Id uint64 `json:"id" yaml:"id"` - PoolParams PoolParams `json:"pool_params" yaml:"pool_params"` - FuturePoolGovernor string `json:"future_pool_governor" yaml:"future_pool_governor"` - TotalWeight sdk.Dec `json:"total_weight" yaml:"total_weight"` - TotalShares sdk.Coin `json:"total_shares" yaml:"total_shares"` - PoolAssets []PoolAsset `json:"pool_assets" yaml:"pool_assets"` -} +// Upstream marshal.go contains balancerPoolPretty and custom +// JSONMarshal and JSONUnmarshal functions. Given that we deal +// directly with the value in the KV store, not the output from +// a query, we do not need to use these methods and they are +// removed below. func (p Pool) String() string { - out, err := p.MarshalJSON() + out, err := json.Marshal(p) if err != nil { panic(err) } return string(out) } - -// MarshalJSON returns the JSON representation of a Pool. -func (p Pool) MarshalJSON() ([]byte, error) { - if len(strings.TrimSpace(p.Address)) == 0 { - return nil, errors.New("empty address string is not allowed") - } - - accAddr, err := sdk.GetFromBech32(p.Address, "osmo") - // accAddr, err := sdk.AccAddressFromBech32(p.Address) - if err != nil { - return nil, err - } - - decTotalWeight := sdk.NewDecFromInt(p.TotalWeight) - - return json.Marshal(balancerPoolPretty{ - Address: accAddr, - Id: p.Id, - PoolParams: p.PoolParams, - FuturePoolGovernor: p.FuturePoolGovernor, - TotalWeight: decTotalWeight, - TotalShares: p.TotalShares, - PoolAssets: p.PoolAssets, - }) -} - -// UnmarshalJSON unmarshals raw JSON bytes into a Pool. -func (p *Pool) UnmarshalJSON(bz []byte) error { - var alias balancerPoolPretty - if err := json.Unmarshal(bz, &alias); err != nil { - return err - } - - p.Address = alias.Address.String() - p.Id = alias.Id - p.PoolParams = alias.PoolParams - p.FuturePoolGovernor = alias.FuturePoolGovernor - p.TotalWeight = alias.TotalWeight.RoundInt() - p.TotalShares = alias.TotalShares - p.PoolAssets = alias.PoolAssets - - return nil -} diff --git a/osmosis-types/gamm/pool-models/balancer/pool.go b/osmosis-types/gamm/pool-models/balancer/pool.go index 23514e7c2..55c3dd058 100644 --- a/osmosis-types/gamm/pool-models/balancer/pool.go +++ b/osmosis-types/gamm/pool-models/balancer/pool.go @@ -12,6 +12,7 @@ import ( "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) //nolint:deadcode @@ -74,7 +75,7 @@ func NewBalancerPool(poolId uint64, balancerPoolParams PoolParams, assets []Pool // GetAddress returns the address of a pool. // If the pool address is not bech32 valid, it returns an empty address. func (p Pool) GetAddress() sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(p.Address) + addr, err := addressutils.AccAddressFromBech32(p.Address, "") if err != nil { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } diff --git a/osmosis-types/gamm/pool-models/stableswap/pool.go b/osmosis-types/gamm/pool-models/stableswap/pool.go index 37498cc50..2e6dacb13 100644 --- a/osmosis-types/gamm/pool-models/stableswap/pool.go +++ b/osmosis-types/gamm/pool-models/stableswap/pool.go @@ -11,6 +11,7 @@ import ( "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/internal/cfmm_common" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) var _ gamm.PoolI = &Pool{} @@ -41,7 +42,7 @@ func NewStableswapPool(poolId uint64, stableswapPoolParams PoolParams, initialLi } func (p Pool) GetAddress() sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(p.Address) + addr, err := addressutils.AccAddressFromBech32(p.Address, "") if err != nil { panic(fmt.Sprintf("could not bech32 decode address of pool with id: %d", p.GetId())) } diff --git a/osmosis-types/validation.go b/osmosis-types/validation.go index 5a3f3351b..333c276bb 100644 --- a/osmosis-types/validation.go +++ b/osmosis-types/validation.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" osmosislockuptypes "github.com/ingenuity-build/quicksilver/osmosis-types/lockup" + "github.com/ingenuity-build/quicksilver/utils" participationrewardstypes "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) @@ -34,9 +35,9 @@ func DetermineApplicableTokensInPool(ctx sdk.Context, prKeeper ParticipationRewa pool, _ := ipool.(*participationrewardstypes.OsmosisPoolProtocolData) poolDenom := "" - for zk, zd := range pool.Zones { - if zk == chainID { - poolDenom = zd + for _, zk := range utils.Keys(pool.Denoms) { + if pool.Denoms[zk].ChainID == chainID { + poolDenom = zk break } } diff --git a/proto/quicksilver/interchainquery/v1/query.proto b/proto/quicksilver/interchainquery/v1/query.proto index e5b035dca..adf51853c 100644 --- a/proto/quicksilver/interchainquery/v1/query.proto +++ b/proto/quicksilver/interchainquery/v1/query.proto @@ -16,7 +16,8 @@ option go_package = "github.com/ingenuity-build/quicksilver/x/interchainquery/ty service QuerySrvr { // Params returns the total set of minting parameters. rpc Queries(QueryRequestsRequest) returns (QueryRequestsResponse) { - option (google.api.http).get = "/quicksilver/interchainquery/v1/queries/{chain_id}"; + option (google.api.http).get = + "/quicksilver/interchainquery/v1/queries/{chain_id}"; } } @@ -29,18 +30,21 @@ message QueryRequestsRequest { // QueryParamsResponse is the response type for the Query/Params RPC method. message QueryRequestsResponse { // params defines the parameters of the module. - repeated quicksilver.interchainquery.v1.Query queries = 1 [(gogoproto.nullable) = false]; + repeated quicksilver.interchainquery.v1.Query queries = 1 + [ (gogoproto.nullable) = false ]; cosmos.base.query.v1beta1.PageResponse pagination = 2; } // GetTxResponse is the response type for the Service.GetTx method. message GetTxWithProofResponse { - // tx is the queried transaction. - cosmos.tx.v1beta1.Tx tx = 1; + // tx is the queried transaction; deprecated. + cosmos.tx.v1beta1.Tx tx = 1; // deprecated, v1.2.13 // tx_response is the queried TxResponses. - cosmos.base.abci.v1beta1.TxResponse tx_response = 2; + cosmos.base.abci.v1beta1.TxResponse tx_response = 2; // deprecated, v1.2.13 // proof is the tmproto.TxProof for the queried tx tendermint.types.TxProof proof = 3; // ibc-go header to validate txs ibc.lightclients.tendermint.v1.Header header = 4; + // tx_bytes is the byte representation of the queried tx + bytes tx_bytes = 5; } diff --git a/proto/quicksilver/interchainstaking/v1/proposals.proto b/proto/quicksilver/interchainstaking/v1/proposals.proto index 9180f8656..730dbad90 100644 --- a/proto/quicksilver/interchainstaking/v1/proposals.proto +++ b/proto/quicksilver/interchainstaking/v1/proposals.proto @@ -14,10 +14,11 @@ message RegisterZoneProposal { string title = 1; string description = 2; - string connection_id = 3 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string base_denom = 4 [(gogoproto.moretags) = "yaml:\"base_denom\""]; - string local_denom = 5 [(gogoproto.moretags) = "yaml:\"local_denom\""]; - string account_prefix = 6 [(gogoproto.moretags) = "yaml:\"account_prefix\""]; + string connection_id = 3 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string base_denom = 4 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ]; + string local_denom = 5 [ (gogoproto.moretags) = "yaml:\"local_denom\"" ]; + string account_prefix = 6 + [ (gogoproto.moretags) = "yaml:\"account_prefix\"" ]; bool multi_send = 7; // deprecated bool liquidity_module = 8; int64 messages_per_tx = 9; @@ -25,26 +26,33 @@ message RegisterZoneProposal { bool deposits_enabled = 11; bool unbonding_enabled = 12; int64 decimals = 13; + bool is_118 = 14; } message RegisterZoneProposalWithDeposit { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string title = 1 [(gogoproto.moretags) = "yaml:\"title\""]; - string description = 2 [(gogoproto.moretags) = "yaml:\"description\""]; - string connection_id = 3 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string base_denom = 4 [(gogoproto.moretags) = "yaml:\"base_denom\""]; - string local_denom = 5 [(gogoproto.moretags) = "yaml:\"local_denom\""]; - string account_prefix = 6 [(gogoproto.moretags) = "yaml:\"account_prefix\""]; - bool multi_send = 7 [(gogoproto.moretags) = "yaml:\"multi_send\""]; - bool liquidity_module = 8 [(gogoproto.moretags) = "yaml:\"liquidity_module\""]; - string deposit = 9 [(gogoproto.moretags) = "yaml:\"deposit\""]; + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + string connection_id = 3 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string base_denom = 4 [ (gogoproto.moretags) = "yaml:\"base_denom\"" ]; + string local_denom = 5 [ (gogoproto.moretags) = "yaml:\"local_denom\"" ]; + string account_prefix = 6 + [ (gogoproto.moretags) = "yaml:\"account_prefix\"" ]; + bool multi_send = 7 [ (gogoproto.moretags) = "yaml:\"multi_send\"" ]; + bool liquidity_module = 8 + [ (gogoproto.moretags) = "yaml:\"liquidity_module\"" ]; + string deposit = 9 [ (gogoproto.moretags) = "yaml:\"deposit\"" ]; int64 messages_per_tx = 10; - bool return_to_sender = 11 [(gogoproto.moretags) = "yaml:\"return_to_sender\""]; - bool deposits_enabled = 12 [(gogoproto.moretags) = "yaml:\"deposits_enabled\""]; - bool unbonding_enabled = 13 [(gogoproto.moretags) = "yaml:\"deposits_enabled\""]; - int64 decimals = 14 [(gogoproto.moretags) = "yaml:\"decimals\""]; + bool return_to_sender = 11 + [ (gogoproto.moretags) = "yaml:\"return_to_sender\"" ]; + bool deposits_enabled = 12 + [ (gogoproto.moretags) = "yaml:\"deposits_enabled\"" ]; + bool unbonding_enabled = 13 + [ (gogoproto.moretags) = "yaml:\"deposits_enabled\"" ]; + int64 decimals = 14 [ (gogoproto.moretags) = "yaml:\"decimals\"" ]; + bool is_118 = 15; } message UpdateZoneProposal { @@ -52,30 +60,32 @@ message UpdateZoneProposal { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; - string title = 1 [(gogoproto.moretags) = "yaml:\"title\""]; - string description = 2 [(gogoproto.moretags) = "yaml:\"description\""]; - string chain_id = 3 [(gogoproto.moretags) = "yaml:\"chain_id\""]; + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + string chain_id = 3 [ (gogoproto.moretags) = "yaml:\"chain_id\"" ]; - repeated UpdateZoneValue changes = 4 [(gogoproto.moretags) = "yaml:\"changes\""]; + repeated UpdateZoneValue changes = 4 + [ (gogoproto.moretags) = "yaml:\"changes\"" ]; } message UpdateZoneProposalWithDeposit { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; - string title = 1 [(gogoproto.moretags) = "yaml:\"title\""]; - string description = 2 [(gogoproto.moretags) = "yaml:\"description\""]; - string chain_id = 3 [(gogoproto.moretags) = "yaml:\"chain_id\""]; + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + string chain_id = 3 [ (gogoproto.moretags) = "yaml:\"chain_id\"" ]; - repeated UpdateZoneValue changes = 4 [(gogoproto.moretags) = "yaml:\"changes\""]; - string deposit = 5 [(gogoproto.moretags) = "yaml:\"deposit\""]; + repeated UpdateZoneValue changes = 4 + [ (gogoproto.moretags) = "yaml:\"changes\"" ]; + string deposit = 5 [ (gogoproto.moretags) = "yaml:\"deposit\"" ]; } // UpdateZoneValue defines an individual parameter change, for use in // UpdateZoneProposal. message UpdateZoneValue { - string key = 1 [(gogoproto.moretags) = "yaml:\"key\""]; - string value = 2 [(gogoproto.moretags) = "yaml:\"value\""]; + string key = 1 [ (gogoproto.moretags) = "yaml:\"key\"" ]; + string value = 2 [ (gogoproto.moretags) = "yaml:\"value\"" ]; } message MsgGovReopenChannel { @@ -85,10 +95,10 @@ message MsgGovReopenChannel { string title = 1; string description = 2; - string connection_id = 3 [(gogoproto.moretags) = "yaml:\"connection_id\""]; - string port_id = 4 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string connection_id = 3 [ (gogoproto.moretags) = "yaml:\"connection_id\"" ]; + string port_id = 4 [ (gogoproto.moretags) = "yaml:\"port_id\"" ]; - string authority = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string authority = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; } // MsgGovReopenChannelResponse defines the MsgGovReopenChannel response type. @@ -101,10 +111,10 @@ message MsgGovCloseChannel { string title = 1; string description = 2; - string channel_id = 3 [(gogoproto.moretags) = "yaml:\"channel_id\""]; - string port_id = 4 [(gogoproto.moretags) = "yaml:\"port_id\""]; + string channel_id = 3 [ (gogoproto.moretags) = "yaml:\"channel_id\"" ]; + string port_id = 4 [ (gogoproto.moretags) = "yaml:\"port_id\"" ]; - string authority = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + string authority = 5 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; } // MsgGovCloseChannelResponse defines the MsgGovCloseChannel response type. diff --git a/proto/quicksilver/participationrewards/v1/participationrewards.proto b/proto/quicksilver/participationrewards/v1/participationrewards.proto index 9838905cf..dccffb8e0 100644 --- a/proto/quicksilver/participationrewards/v1/participationrewards.proto +++ b/proto/quicksilver/participationrewards/v1/participationrewards.proto @@ -28,16 +28,6 @@ message DistributionProportions { ]; } -// Params holds parameters for the participationrewards module. -message Params_v1 { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - - // distribution_proportions defines the proportions of the minted - // participation rewards; - DistributionProportions distribution_proportions = 1 [(gogoproto.nullable) = false]; -} - // Params holds parameters for the participationrewards module. message Params { option (gogoproto.goproto_getters) = false; @@ -45,7 +35,8 @@ message Params { // distribution_proportions defines the proportions of the minted // participation rewards; - DistributionProportions distribution_proportions = 1 [(gogoproto.nullable) = false]; + DistributionProportions distribution_proportions = 1 + [ (gogoproto.nullable) = false ]; bool claims_enabled = 2; } @@ -58,7 +49,7 @@ message KeyedProtocolData { // determination of rewards. message ProtocolData { string type = 1; - bytes data = 2 [(gogoproto.casttype) = "encoding/json.RawMessage"]; + bytes data = 2 [ (gogoproto.casttype) = "encoding/json.RawMessage" ]; } enum ProtocolDataType { diff --git a/utils/address.go b/utils/address.go deleted file mode 100644 index 5bc0a6c10..000000000 --- a/utils/address.go +++ /dev/null @@ -1,107 +0,0 @@ -package utils - -import ( - "crypto/rand" - "errors" - "fmt" - "strings" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" -) - -func AccAddressFromBech32(address, checkHRP string) (addr sdk.AccAddress, err error) { - if strings.TrimSpace(address) == "" { - return sdk.AccAddress{}, errors.New("empty address string is not allowed") - } - - hrp, bz, err := bech32.DecodeAndConvert(address) - if err != nil { - return nil, err - } - - if checkHRP != "" { - if checkHRP != hrp { - return sdk.AccAddress{}, fmt.Errorf("unexpected hrp - got %s expected %s", hrp, checkHRP) - } - } - - err = sdk.VerifyAddressFormat(bz) - if err != nil { - return nil, err - } - - return sdk.AccAddress(bz), nil -} - -func ValAddressFromBech32(address, checkHRP string) (addr sdk.ValAddress, err error) { - if strings.TrimSpace(address) == "" { - return sdk.ValAddress{}, errors.New("empty address string is not allowed") - } - - hrp, bz, err := bech32.DecodeAndConvert(address) - if err != nil { - return nil, err - } - - if checkHRP != "" { - if checkHRP != hrp { - return sdk.ValAddress{}, fmt.Errorf("unexpected hrp - got %s expected %s", hrp, checkHRP) - } - } - - err = sdk.VerifyAddressFormat(bz) - if err != nil { - return nil, err - } - - return sdk.ValAddress(bz), nil -} - -func GenerateAccAddressForTest() sdk.AccAddress { - size := 32 // change the length of the generated random string here - - rb := make([]byte, size) - _, err := rand.Read(rb) - if err != nil { - panic(err) - } - - return sdk.AccAddress(rb) -} - -func GenerateValAddressForTest() sdk.ValAddress { - size := 32 // change the length of the generated random string here - - rb := make([]byte, size) - _, err := rand.Read(rb) - if err != nil { - panic(err) - } - - return sdk.ValAddress(rb) -} - -func GenerateValAddressForTestWithPrefix(hrp string) string { - addr, err := bech32.ConvertAndEncode(hrp, GenerateValAddressForTest()) - if err != nil { - panic(err) - } - return addr -} - -func GenerateAccAddressForTestWithPrefix(hrp string) string { - addr, err := bech32.ConvertAndEncode(hrp, GenerateAccAddressForTest()) - if err != nil { - panic(err) - } - return addr -} - -func ConvertAccAddressForTestUsingPrefix(address sdk.AccAddress, prefix string) string { - addr, err := bech32.ConvertAndEncode(prefix, address) - if err != nil { - panic(err) - } - return addr -} diff --git a/utils/addressutils/address.go b/utils/addressutils/address.go new file mode 100644 index 000000000..f20e1c41b --- /dev/null +++ b/utils/addressutils/address.go @@ -0,0 +1,110 @@ +package addressutils + +import ( + "errors" + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/ingenuity-build/quicksilver/utils/randomutils" +) + +// AddressFromBech32 decodes a bech32 encoded address into a byte-slice, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Returns an error if address is zero-length, invalid or the prefix does not match. +func AddressFromBech32(address, prefix string) (addr []byte, err error) { + if strings.TrimSpace(address) == "" { + return nil, errors.New("empty address string is not allowed") + } + + hrp, bz, err := bech32.DecodeAndConvert(address) + if err != nil { + return nil, err + } + + if prefix != "" { + if prefix != hrp { + return nil, fmt.Errorf("unexpected prefix - got %s expected %s", hrp, prefix) + } + } + + err = sdk.VerifyAddressFormat(bz) + if err != nil { + return nil, err + } + + return bz, nil +} + +// AccAddressFromBech32 decodes a bech32 encoded address into an sdk.AccAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Returns an error if address is zero-length, invalid or the prefix does not match. +func AccAddressFromBech32(address, prefix string) (sdk.AccAddress, error) { + addr, err := AddressFromBech32(address, prefix) + return sdk.AccAddress(addr), err +} + +// MustAccAddressFromBech32 decodes a bech32 encoded address into an sdk.AccAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Panics if address is zero-length, invalid or the prefix does not match. +func MustAccAddressFromBech32(address, prefix string) sdk.AccAddress { + accAddress, err := AccAddressFromBech32(address, prefix) + if err != nil { + panic(err) + } + return accAddress +} + +// ValAddressFromBech32 decodes a bech32 encoded address into an sdk.ValAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Returns an error if address is zero-length, invalid or the prefix does not match. +func ValAddressFromBech32(address, prefix string) (sdk.ValAddress, error) { + addr, err := AddressFromBech32(address, prefix) + return sdk.ValAddress(addr), err +} + +// MustValAddressFromBech32 decodes a bech32 encoded address into an sdk.ValAddress, and validates the prefix (hrp). +// An empty prefix param skips the checking. +// Panics if address is zero-length, invalid or the prefix does not match. +func MustValAddressFromBech32(address, prefix string) sdk.ValAddress { + valAddress, err := ValAddressFromBech32(address, prefix) + if err != nil { + panic(err) + } + return valAddress +} + +// GenerateAccAddressForTest generates a random sdk.AccAddress for test purposes. +func GenerateAccAddressForTest() sdk.AccAddress { + return sdk.AccAddress(randomutils.GenerateRandomBytes(32)) +} + +// GenerateValAddressForTest generates a random sdk.ValAddress for test purposes. +func GenerateValAddressForTest() sdk.ValAddress { + return sdk.ValAddress(randomutils.GenerateRandomBytes(32)) +} + +// GenerateAddressForTestWithPrefix generates a random bech32 address with the specified prefix for test purposes. +func GenerateAddressForTestWithPrefix(prefix string) string { + // AccAddress and ValAddress are simple a byte slice, so it doesn't matter this is AccAddress below. + return MustEncodeAddressToBech32(prefix, GenerateAccAddressForTest()) +} + +// EncodeAddressToBech32 encodes an sdk.Address interface with the specified prefix. +// Identical behaviour to bech32.ConvertAndDecode(); added to addressutils for consistency. +// Error is thrown if encoding fails. +func EncodeAddressToBech32(prefix string, address sdk.Address) (string, error) { + return bech32.ConvertAndEncode(prefix, address.Bytes()) +} + +// EncodeAddressToBech32 encodes an sdk.Address interface with the specified prefix. +// Identical behaviour to bech32.ConvertAndDecode(); added to addressutils for consistency. +// Panics if encoding fails. +func MustEncodeAddressToBech32(prefix string, address sdk.Address) string { + addr, err := EncodeAddressToBech32(prefix, address) + if err != nil { + panic(err) + } + return addr +} diff --git a/utils/addressutils/address_test.go b/utils/addressutils/address_test.go new file mode 100644 index 000000000..92bf4663b --- /dev/null +++ b/utils/addressutils/address_test.go @@ -0,0 +1,194 @@ +package addressutils_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/ingenuity-build/quicksilver/utils/addressutils" +) + +func TestAddressFromBech32(t *testing.T) { + cases := []struct { + name string + address string + prefix string + expectedBytes []byte + expectedErr string + }{ + { + "invalid - empty string", + "", + "", + nil, + "empty address string is not allowed", + }, + { + "invalid - invalid address", + "quick", + "", + nil, + "decoding bech32 failed: invalid bech32 string length 5", + }, + { + "invalid - invalid characters", + "sbg2apkjme1qh2ycto7jn30nu", + "", + nil, + "decoding bech32 failed: invalid character not part of charset: 111", + }, + { + "invalid - invalid checksum", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28caaaaaa", + "", + nil, + "decoding bech32 failed: invalid checksum (expected 098lr8 got aaaaaa)", + }, + { + "invalid - invalid separator", + "cosmos2kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "", + nil, + "decoding bech32 failed: invalid separator index -1", + }, + { + "invalid - invalid hrp", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "quick", + nil, + "unexpected prefix - got cosmos expected quick", + }, + { + "invalid - no prefix", + "1kv4ez0rgrd679m6da96apnqxkcamh28c00j09s", + "quick", + nil, + "decoding bech32 failed: invalid separator index 0", + }, + { + "invalid - too long", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh0rgrd6grd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxk79m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd6nqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6danqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da96apnqxkcamh0rgrd679m6da79m6da96apnqxkcamh28cc63a68", + "", + nil, + "decoding bech32 failed: invalid bech32 string length 4393", + }, + { + "valid - no check", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "", + }, + { + "valid - with hrp check", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "cosmos", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "", + }, + } + + for _, c := range cases { + addr, err := addressutils.AccAddressFromBech32(c.address, c.prefix) + + if c.expectedErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, c.expectedErr) + } else { + require.Equal(t, c.expectedBytes, addr.Bytes()) + } + + valaddr, err := addressutils.ValAddressFromBech32(c.address, c.prefix) + + if c.expectedErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, c.expectedErr) + } else { + require.Equal(t, c.expectedBytes, valaddr.Bytes()) + } + + if c.expectedErr != "" { + require.Panics(t, func() { addressutils.MustAccAddressFromBech32(c.address, c.prefix) }) + require.Panics(t, func() { addressutils.MustValAddressFromBech32(c.address, c.prefix) }) + } else { + addr := addressutils.MustAccAddressFromBech32(c.address, c.prefix) + require.Equal(t, c.expectedBytes, addr.Bytes()) + + valaddr := addressutils.MustValAddressFromBech32(c.address, c.prefix) + require.Equal(t, c.expectedBytes, valaddr.Bytes()) + } + } +} + +func TestGenerateAccAddressForTest(t *testing.T) { + address := addressutils.GenerateAccAddressForTest() + require.Equal(t, 32, len(address.Bytes())) + err := sdk.VerifyAddressFormat(address.Bytes()) + require.NoError(t, err) +} + +func TestGenerateValAddressForTest(t *testing.T) { + address := addressutils.GenerateValAddressForTest() + require.Equal(t, 32, len(address.Bytes())) + err := sdk.VerifyAddressFormat(address.Bytes()) + require.NoError(t, err) +} + +func TestGenerateAddressForTestWithPrefix(t *testing.T) { + b32addr := addressutils.GenerateAddressForTestWithPrefix("cosmos") + _, err := addressutils.AddressFromBech32(b32addr, "cosmos") + require.NoError(t, err) +} + +func TestEncodeAddressToBech32(t *testing.T) { + cases := []struct { + name string + addrBytes []byte + prefix string + expectedAddress string + expectedErr string + }{ + { + "valid", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "cosmos", + "cosmos1kv4ez0rgrd679m6da96apnqxkcamh28c098lr8", + "", + }, + { + "surprisingly valid, single null byte", + []byte{0x00}, + "cosmos", + "cosmos1qqxuevtt", + "", + }, + { + "surprisingly valid, nil", + nil, + "cosmos", + "cosmos1550dq7", + "", + }, + { + "even more surprisingly valid - no hrp :/", + []byte{0xb3, 0x2b, 0x91, 0x3c, 0x68, 0x1b, 0x75, 0xe2, 0xef, 0x4d, 0xe9, 0x75, 0xd0, 0xcc, 0x6, 0xb6, 0x3b, 0xbb, 0xa8, 0xf8}, + "", + "1kv4ez0rgrd679m6da96apnqxkcamh28cjkahle", + "", + }, + } + + for _, c := range cases { + addr, err := addressutils.EncodeAddressToBech32(c.prefix, sdk.AccAddress(c.addrBytes)) + + if c.expectedErr != "" { + require.Error(t, err) + require.ErrorContains(t, err, c.expectedErr) + + require.Panics(t, func() { addressutils.MustEncodeAddressToBech32(c.prefix, sdk.AccAddress(c.addrBytes)) }) + } else { + require.Equal(t, c.expectedAddress, addr) + } + } +} diff --git a/utils/coins_test.go b/utils/coins_test.go index 28ab25530..3858e93e6 100644 --- a/utils/coins_test.go +++ b/utils/coins_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" utils "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) const expectedDenom = "denom" @@ -21,7 +22,7 @@ func TestDenomFromRequestKey(t *testing.T) { { "valid", func() (sdk.AccAddress, []byte) { - accAddr := utils.GenerateAccAddressForTest() + accAddr := addressutils.GenerateAccAddressForTest() key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) key = append(key, []byte(expectedDenom)...) return accAddr, key @@ -31,9 +32,9 @@ func TestDenomFromRequestKey(t *testing.T) { { "invalid - address mismatch", func() (sdk.AccAddress, []byte) { - keyAddr, err := utils.AccAddressFromBech32("cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh", "cosmos") + keyAddr, err := addressutils.AccAddressFromBech32("cosmos135rd8ft0dyq8fv3w3hhmaa55qu3pe668j99qh67mg747ew4ad03qsgq8vh", "cosmos") require.NoError(t, err) - checkAddr, err := utils.AccAddressFromBech32("cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", "cosmos") + checkAddr, err := addressutils.AccAddressFromBech32("cosmos1ent5eg0xn3pskf3fhdw8mky88ry7t4kx628ru3pzp4nqjp6eufusphlldy", "cosmos") require.NoError(t, err) key := banktypes.CreateAccountBalancesPrefix(keyAddr.Bytes()) key = append(key, []byte(expectedDenom)...) @@ -54,7 +55,7 @@ func TestDenomFromRequestKey(t *testing.T) { { "invalid - empty denom", func() (sdk.AccAddress, []byte) { - accAddr := utils.GenerateAccAddressForTest() + accAddr := addressutils.GenerateAccAddressForTest() key := banktypes.CreateAccountBalancesPrefix(accAddr.Bytes()) key = append(key, []byte("")...) return accAddr, key diff --git a/utils/test.go b/utils/randomutils/random.go similarity index 50% rename from utils/test.go rename to utils/randomutils/random.go index e199a5d0a..bfee503e1 100644 --- a/utils/test.go +++ b/utils/randomutils/random.go @@ -1,34 +1,25 @@ -package utils +package randomutils import ( "crypto/rand" "encoding/hex" ) -func GenerateRandomHash() []byte { - bytes := make([]byte, 32) - _, err := rand.Read(bytes) - if err != nil { - panic("unable to read random bytes") - } - return bytes -} - -func GenerateRandomHashAsHex() string { - return hex.EncodeToString(GenerateRandomHash()) -} - // GenerateRandomBytes returns securely generated random bytes. -// It will return an error if the system's secure random +// It will panic if the system's secure random // number generator fails to function correctly, in which // case the caller should not continue. -func GenerateRandomBytes(n int) ([]byte, error) { +func GenerateRandomBytes(n int) []byte { b := make([]byte, n) _, err := rand.Read(b) // Note that err == nil only if we read len(b) bytes. if err != nil { - return nil, err + panic("unable to read random bytes") } - return b, nil + return b +} + +func GenerateRandomHashAsHex(n int) string { + return hex.EncodeToString(GenerateRandomBytes(n)) } diff --git a/utils/randomutils/random_test.go b/utils/randomutils/random_test.go new file mode 100644 index 000000000..d692bd294 --- /dev/null +++ b/utils/randomutils/random_test.go @@ -0,0 +1,27 @@ +package randomutils_test + +import ( + "encoding/hex" + "math/rand" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/ingenuity-build/quicksilver/utils/randomutils" +) + +func TestGenerateRandomHash(t *testing.T) { + random := rand.New(rand.NewSource(time.Now().UnixNano())) + b := random.Intn(128) + byteslice := randomutils.GenerateRandomBytes(b) + require.Equal(t, b, len(byteslice)) +} + +func TestGenerateRandomHashAsHex(t *testing.T) { + hexHash := randomutils.GenerateRandomHashAsHex(32) + require.Equal(t, 64, len(hexHash)) + byteslice, err := hex.DecodeString(hexHash) + require.NoError(t, err) + require.Equal(t, 32, len(byteslice)) +} diff --git a/x/airdrop/keeper/msg_server_test.go b/x/airdrop/keeper/msg_server_test.go index ef6dad7ea..3c8918cd5 100644 --- a/x/airdrop/keeper/msg_server_test.go +++ b/x/airdrop/keeper/msg_server_test.go @@ -8,7 +8,7 @@ import ( minttypes "github.com/ingenuity-build/quicksilver/x/mint/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" "github.com/ingenuity-build/quicksilver/x/airdrop/types" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" @@ -18,7 +18,7 @@ import ( func (s *KeeperTestSuite) Test_msgServer_Claim() { appA := s.GetQuicksilverApp(s.chainA) - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() denom := "uatom" // same as test zone setup in keeper_test msg := types.MsgClaim{} @@ -492,7 +492,7 @@ func (s *KeeperTestSuite) Test_msgServer_IncentivePoolSpend() { appA := s.GetQuicksilverApp(s.chainA) modAccAddr := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() denom := "uatom" // same as test zone setup in keeper_test coins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromUint64(1000))) mintCoins := sdk.NewCoins(sdk.NewCoin(denom, sdk.NewIntFromUint64(100000000))) diff --git a/x/airdrop/keeper/proposal_handler_test.go b/x/airdrop/keeper/proposal_handler_test.go index 8f621b24f..fd67cb379 100644 --- a/x/airdrop/keeper/proposal_handler_test.go +++ b/x/airdrop/keeper/proposal_handler_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/airdrop/keeper" "github.com/ingenuity-build/quicksilver/x/airdrop/types" ) @@ -35,7 +35,7 @@ func (s *KeeperTestSuite) TestHandleRegisterZoneDropProposal() { IsConcluded: false, } userAddresses := []string{ - utils.GenerateAccAddressForTest().String(), + addressutils.GenerateAccAddressForTest().String(), } prop := types.RegisterZoneDropProposal{} diff --git a/x/airdrop/types/messages.pb.go b/x/airdrop/types/messages.pb.go index 9dc1eb326..901960934 100644 --- a/x/airdrop/types/messages.pb.go +++ b/x/airdrop/types/messages.pb.go @@ -202,46 +202,46 @@ func init() { var fileDescriptor_2b0828c7de1949a1 = []byte{ // 659 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x3d, 0x6f, 0x13, 0x4d, - 0x10, 0xf6, 0xd9, 0x79, 0xf3, 0xb1, 0xaf, 0xde, 0x0f, 0x8e, 0x10, 0x1c, 0x0b, 0xee, 0xac, 0x43, - 0x91, 0x4c, 0x90, 0xef, 0xe2, 0x00, 0x41, 0x72, 0x87, 0x43, 0x93, 0x22, 0x28, 0x72, 0x3a, 0x1a, - 0x6b, 0x7d, 0xb7, 0x6c, 0x56, 0xb9, 0xdb, 0x39, 0x6e, 0xd7, 0x56, 0xdc, 0xa1, 0x48, 0x48, 0x94, - 0x48, 0xfc, 0x81, 0xd4, 0x54, 0x14, 0x88, 0x9e, 0x2e, 0x65, 0x04, 0x0d, 0x95, 0x41, 0x09, 0x12, - 0xd4, 0xf9, 0x05, 0xe8, 0xf6, 0xf6, 0x1c, 0x5b, 0x84, 0x44, 0x54, 0xde, 0x9b, 0x79, 0x9e, 0xf9, - 0x78, 0x66, 0xc6, 0x68, 0xe9, 0x59, 0x8f, 0xf9, 0xbb, 0x82, 0x85, 0x7d, 0x92, 0x78, 0x98, 0x25, - 0x41, 0x02, 0xb1, 0xd7, 0x6f, 0x78, 0x11, 0x11, 0x02, 0x53, 0x22, 0xdc, 0x38, 0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 0x9e, 0x53, 0x29, 0xcb, 0xe8, 0x9d, 0x08, 0x20, 0xe8, 0x88, 0x24, 0x40, 0xd3, 0xa8, + 0xb5, 0x36, 0x0f, 0x8e, 0xca, 0xc6, 0xe1, 0x51, 0xd9, 0xf8, 0x7e, 0x54, 0x36, 0xde, 0x1c, 0x97, + 0x73, 0x87, 0xc7, 0xe5, 0xdc, 0xd7, 0xe3, 0x72, 0xee, 0xd9, 0xea, 0xd8, 0x20, 0x19, 0xa7, 0x84, + 0xf7, 0x98, 0x1c, 0xd4, 0xbb, 0x3d, 0x16, 0xf8, 0x13, 0x79, 0x76, 0x47, 0x39, 0xd4, 0x70, 0xbb, + 0xd3, 0xea, 0x2f, 0xe1, 0xfe, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb2, 0xf6, 0x4f, 0x1d, 0x0d, 0x05, 0x00, 0x00, } diff --git a/x/airdrop/types/msgs_test.go b/x/airdrop/types/msgs_test.go index 77c7ad289..e9bb4b02e 100644 --- a/x/airdrop/types/msgs_test.go +++ b/x/airdrop/types/msgs_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/airdrop/types" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -219,8 +219,8 @@ func TestMsgIncentivePoolSpendValidateBasic(t *testing.T) { } validTestCoins := sdk.NewCoins(sdk.NewCoin("test", sdk.NewIntFromUint64(10000))) - addr1 := utils.GenerateAccAddressForTest().String() - addr2 := utils.GenerateAccAddressForTest().String() + addr1 := addressutils.GenerateAccAddressForTest().String() + addr2 := addressutils.GenerateAccAddressForTest().String() tests := []struct { name string diff --git a/x/claimsmanager/keeper/claims_test.go b/x/claimsmanager/keeper/claims_test.go index 4dc403524..a343342f1 100644 --- a/x/claimsmanager/keeper/claims_test.go +++ b/x/claimsmanager/keeper/claims_test.go @@ -1,7 +1,7 @@ package keeper_test import ( - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -24,7 +24,7 @@ var testClaims = []types.Claim{ }, // random user claim on chainB (using osmosis pool) { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), // ChainID: suite.chainB.ChainID, Module: types.ClaimTypeOsmosisPool, SourceChainId: "osmosis-1", @@ -48,7 +48,7 @@ var testClaims = []types.Claim{ }, // random user claim on "cosmoshub-4" (liquid) { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainId: "cosmoshub-4", Module: types.ClaimTypeLiquidToken, SourceChainId: "", diff --git a/x/claimsmanager/keeper/keeper_test.go b/x/claimsmanager/keeper/keeper_test.go index 05d531da6..e955a82f0 100644 --- a/x/claimsmanager/keeper/keeper_test.go +++ b/x/claimsmanager/keeper/keeper_test.go @@ -8,11 +8,11 @@ import ( "github.com/stretchr/testify/suite" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -var testAddress = utils.GenerateAccAddressForTest().String() +var testAddress = addressutils.GenerateAccAddressForTest().String() func init() { ibctesting.DefaultTestingAppInit = app.SetupTestingApp diff --git a/x/claimsmanager/types/claimsmanager_test.go b/x/claimsmanager/types/claimsmanager_test.go index ac8ef1619..2178cd5f6 100644 --- a/x/claimsmanager/types/claimsmanager_test.go +++ b/x/claimsmanager/types/claimsmanager_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -37,7 +37,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "invalid_chain_id", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "", Amount: 10000, }, @@ -46,7 +46,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "invalid_chain_id", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "", Amount: 10000, }, @@ -55,7 +55,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "invalid_amount", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "testzone-1", Amount: 0, }, @@ -64,7 +64,7 @@ func TestClaim_ValidateBasic(t *testing.T) { { "valid", fields{ - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainID: "testzone-1", Amount: 1000000, }, diff --git a/x/claimsmanager/types/codec.go b/x/claimsmanager/types/codec.go index fdc302f4f..a0a97fc44 100644 --- a/x/claimsmanager/types/codec.go +++ b/x/claimsmanager/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" + "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/stableswap" ) var ( @@ -22,6 +23,7 @@ func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { func RegisterInterfaces(registry types.InterfaceRegistry) { gamm.RegisterInterfaces(registry) balancer.RegisterInterfaces(registry) + stableswap.RegisterInterfaces(registry) // cosmos.base.v1beta1.Msg registry.RegisterImplementations( diff --git a/x/claimsmanager/types/genesis_test.go b/x/claimsmanager/types/genesis_test.go index 1491a3634..63d526959 100644 --- a/x/claimsmanager/types/genesis_test.go +++ b/x/claimsmanager/types/genesis_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) @@ -43,7 +43,7 @@ func TestGenesisState_Validate(t *testing.T) { Params: types.DefaultParams(), Claims: []*types.Claim{ { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainId: "testzone-1", Amount: 0, }, @@ -57,7 +57,7 @@ func TestGenesisState_Validate(t *testing.T) { Params: types.DefaultParams(), Claims: []*types.Claim{ { - UserAddress: utils.GenerateAccAddressForTest().String(), + UserAddress: addressutils.GenerateAccAddressForTest().String(), ChainId: "testzone-1", Amount: 1000000, }, diff --git a/x/claimsmanager/types/keys_test.go b/x/claimsmanager/types/keys_test.go index d5d87d974..ad1e6f408 100644 --- a/x/claimsmanager/types/keys_test.go +++ b/x/claimsmanager/types/keys_test.go @@ -5,12 +5,12 @@ import ( "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" ) func TestKeys(t *testing.T) { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() // zone prefixClaim := types.GetPrefixClaim("testzone-1") @@ -34,7 +34,7 @@ func TestKeys(t *testing.T) { } func TestLastEpochKeys(t *testing.T) { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() // zone prefixClaim := types.GetPrefixLastEpochClaim("testzone-1") diff --git a/x/interchainquery/types/messages.pb.go b/x/interchainquery/types/messages.pb.go index 799f572bd..da9b353d3 100644 --- a/x/interchainquery/types/messages.pb.go +++ b/x/interchainquery/types/messages.pb.go @@ -149,13 +149,13 @@ var fileDescriptor_0640fcbc3e895a79 = []byte{ 0x09, 0xca, 0x48, 0xb0, 0x9b, 0xd1, 0xb9, 0xd4, 0xa9, 0xbc, 0x9e, 0x7a, 0x85, 0x77, 0x53, 0x0f,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x02, 0x03, 0x79, 0x03, 0x00, 0x00, + 0x3a, 0xbd, 0x58, 0x6d, 0x92, 0x60, 0xd9, 0x2f, 0xeb, 0xd5, 0xbd, 0xff, 0x2b, 0x00, 0x00, 0xff, + 0xff, 0x80, 0xb2, 0x83, 0xbd, 0x79, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/interchainquery/types/msgs_test.go b/x/interchainquery/types/msgs_test.go index b4497f625..f4a968ae8 100644 --- a/x/interchainquery/types/msgs_test.go +++ b/x/interchainquery/types/msgs_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainquery/keeper" "github.com/ingenuity-build/quicksilver/x/interchainquery/types" ) @@ -21,7 +21,7 @@ var ( chainB *ibctesting.TestChain path *ibctesting.Path - testAddress sdk.AccAddress = utils.GenerateAccAddressForTest() + testAddress sdk.AccAddress = addressutils.GenerateAccAddressForTest() ) func init() { diff --git a/x/interchainquery/types/query.pb.go b/x/interchainquery/types/query.pb.go index 2337d7f60..0e1dd423a 100644 --- a/x/interchainquery/types/query.pb.go +++ b/x/interchainquery/types/query.pb.go @@ -143,7 +143,7 @@ func (m *QueryRequestsResponse) GetPagination() *query.PageResponse { // GetTxResponse is the response type for the Service.GetTx method. type GetTxWithProofResponse struct { - // tx is the queried transaction. + // tx is the queried transaction; deprecated. Tx *tx.Tx `protobuf:"bytes,1,opt,name=tx,proto3" json:"tx,omitempty"` // tx_response is the queried TxResponses. TxResponse *types.TxResponse `protobuf:"bytes,2,opt,name=tx_response,json=txResponse,proto3" json:"tx_response,omitempty"` @@ -151,6 +151,8 @@ type GetTxWithProofResponse struct { Proof *types1.TxProof `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"` // ibc-go header to validate txs Header *types2.Header `protobuf:"bytes,4,opt,name=header,proto3" json:"header,omitempty"` + // tx_bytes is the byte representation of the queried tx + TxBytes []byte `protobuf:"bytes,5,opt,name=tx_bytes,json=txBytes,proto3" json:"tx_bytes,omitempty"` } func (m *GetTxWithProofResponse) Reset() { *m = GetTxWithProofResponse{} } @@ -214,6 +216,13 @@ func (m *GetTxWithProofResponse) GetHeader() *types2.Header { return nil } +func (m *GetTxWithProofResponse) GetTxBytes() []byte { + if m != nil { + return m.TxBytes + } + return nil +} + func init() { proto.RegisterType((*QueryRequestsRequest)(nil), "quicksilver.interchainquery.v1.QueryRequestsRequest") proto.RegisterType((*QueryRequestsResponse)(nil), "quicksilver.interchainquery.v1.QueryRequestsResponse") @@ -225,43 +234,45 @@ func init() { } var fileDescriptor_e4aadfdae61bcbb1 = []byte{ - // 576 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0xad, 0xbb, 0xb1, 0x31, 0xf7, 0x16, 0x6d, 0xa8, 0xab, 0x50, 0xa8, 0x0a, 0x83, 0x6a, 0x12, - 0xb6, 0x5a, 0xca, 0x85, 0xc3, 0x0e, 0x93, 0xc6, 0xe0, 0xb6, 0x85, 0x4a, 0x20, 0x2e, 0x53, 0x92, - 0x9a, 0xd4, 0xa2, 0xb5, 0xd3, 0xf8, 0x4b, 0x94, 0x0a, 0x71, 0xe1, 0x17, 0x20, 0xf1, 0x23, 0xb8, - 0xf3, 0x0b, 0x38, 0xee, 0x38, 0x89, 0x0b, 0x27, 0x84, 0x5a, 0xfe, 0x03, 0x57, 0x14, 0xc7, 0xcd, - 0xd2, 0x22, 0xb1, 0x71, 0x69, 0xed, 0xf8, 0xbd, 0xf7, 0xbd, 0xef, 0xf9, 0x4b, 0xf0, 0xfe, 0x24, - 0xe6, 0xfe, 0x5b, 0xc5, 0x47, 0x09, 0x8b, 0x28, 0x17, 0xc0, 0x22, 0x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, 0xed, 0x5d, 0xeb, 0x4a, 0x56, 0xc6, 0xaa, 0xf1, - 0xf8, 0x3f, 0x59, 0x79, 0xdf, 0xad, 0x27, 0x1f, 0xbe, 0xfd, 0xfa, 0x54, 0xed, 0x59, 0x5d, 0x7a, - 0x8d, 0x0f, 0x04, 0x67, 0x8a, 0xbe, 0x5b, 0x0c, 0xdd, 0xfb, 0xc3, 0x57, 0xe7, 0x33, 0x1b, 0x5d, - 0xcc, 0x6c, 0xf4, 0x73, 0x66, 0xa3, 0x8f, 0x73, 0xbb, 0x72, 0x31, 0xb7, 0x2b, 0xdf, 0xe7, 0x76, - 0xe5, 0xf5, 0x41, 0xc0, 0x61, 0x18, 0x7b, 0xc4, 0x97, 0x63, 0xca, 0x45, 0xc0, 0x44, 0xcc, 0x61, - 0xfa, 0xd0, 0x8b, 0xf9, 0x68, 0xb0, 0x54, 0x27, 0xfd, 0xab, 0x92, 0xce, 0xda, 0xdb, 0xd0, 0xaf, - 0xd0, 0xa3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xd9, 0xbc, 0x02, 0xb6, 0x04, 0x00, 0x00, + // 595 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0x8e, 0xdd, 0x9f, 0xd0, 0x2d, 0x27, 0xab, 0x45, 0x6e, 0x84, 0x4c, 0x14, 0x28, 0x44, 0x95, + 0xd8, 0x55, 0x42, 0xb9, 0x70, 0xe8, 0xa1, 0x52, 0x29, 0xdc, 0x5a, 0x53, 0x09, 0xc4, 0xa5, 0xb2, + 0x9d, 0xc5, 0x59, 0x91, 0xee, 0x3a, 0xde, 0xb1, 0xb5, 0x11, 0xe2, 0xc2, 0x13, 0x20, 0x78, 0x08, + 0xee, 0x3c, 0x01, 0xc7, 0x1e, 0x2b, 0x71, 0xe1, 0x84, 0x50, 0xc2, 0x83, 0x20, 0xaf, 0x37, 0xa9, + 0x13, 0x24, 0x5a, 0x2e, 0xc9, 0x8e, 0xf7, 0x9b, 0x6f, 0xbe, 0xf9, 0x66, 0x6c, 0xb4, 0x33, 0xcc, + 0x58, 0xf4, 0x56, 0xb2, 0x41, 0x4e, 0x53, 0xc2, 0x38, 0xd0, 0x34, 0xea, 0x07, 0x8c, 0x0f, 0x33, + 0x9a, 0x8e, 0x48, 0xde, 0x21, 0xfa, 0x80, 0x93, 0x54, 0x80, 0x70, 0xbc, 0x0a, 0x16, 0x2f, 0x60, + 0x71, 0xde, 0x69, 0xdc, 0x8d, 0x84, 0x3c, 0x13, 0x92, 0x84, 0x81, 0xa4, 0x24, 0x08, 0x23, 0x46, + 0xf2, 0x4e, 0x48, 0x21, 0xe8, 0xe8, 0xa0, 0x24, 0x69, 0xec, 0x54, 0x41, 0xd3, 0x32, 0x25, 0x2a, + 0x09, 0x62, 0xc6, 0x03, 0x60, 0x82, 0x1b, 0x6c, 0xc3, 0x60, 0x41, 0xcd, 0x30, 0xa0, 0xcc, 0xdd, + 0x46, 0x2c, 0x62, 0xa1, 0x8f, 0xa4, 0x38, 0x99, 0xa7, 0xb7, 0x63, 0x21, 0xe2, 0x01, 0x25, 0x41, + 0xc2, 0x48, 0xc0, 0xb9, 0x00, 0x4d, 0x27, 0xcd, 0x2d, 0x61, 0x61, 0x44, 0x06, 0x2c, 0xee, 0x43, + 0x34, 0x60, 0x94, 0x83, 0x24, 0x40, 0x79, 0x8f, 0xa6, 0x67, 0x8c, 0x43, 0xd1, 0xec, 0x65, 0x64, + 0x12, 0x76, 0xaf, 0x70, 0x67, 0xd1, 0x04, 0x23, 0xa2, 0xc2, 0x0a, 0xa3, 0x84, 0xca, 0xf2, 0xb7, + 0xbc, 0x6d, 0x8d, 0xd0, 0xc6, 0x71, 0x01, 0xf6, 0xe9, 0x30, 0xa3, 0x12, 0xa4, 0xf9, 0x77, 0x9e, + 0x22, 0x74, 0x69, 0x80, 0x6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0x64, 0x61, 0x84, 0xab, 0x4b, 0x57, 0xa5, + 0xc8, 0x3b, 0xf8, 0x99, 0x46, 0xfb, 0x26, 0xab, 0x18, 0x1f, 0xa8, 0xd3, 0x70, 0x04, 0x54, 0xba, + 0x2b, 0x4d, 0xab, 0x7d, 0xd3, 0xaf, 0x83, 0xda, 0x2f, 0xc2, 0xee, 0x37, 0x0b, 0xad, 0x69, 0xdb, + 0x5f, 0xa4, 0x79, 0xea, 0x7c, 0xb5, 0x50, 0xfd, 0xd8, 0xf8, 0xbe, 0x7b, 0xad, 0x69, 0x2d, 0x6c, + 0x5c, 0xe3, 0xf1, 0x7f, 0x66, 0x95, 0x96, 0xb4, 0x9e, 0x7c, 0xf8, 0xfe, 0xfb, 0xb3, 0xbd, 0xeb, + 0x74, 0xc9, 0x35, 0xbe, 0x1d, 0x8c, 0x4a, 0xf2, 0x6e, 0xba, 0x8f, 0xef, 0xf7, 0x5f, 0x9d, 0x8f, + 0x3d, 0xeb, 0x62, 0xec, 0x59, 0xbf, 0xc6, 0x9e, 0xf5, 0x71, 0xe2, 0xd5, 0x2e, 0x26, 0x5e, 0xed, + 0xc7, 0xc4, 0xab, 0xbd, 0xde, 0x8b, 0x19, 0xf4, 0xb3, 0x10, 0x47, 0xe2, 0x8c, 0x30, 0x1e, 0x53, + 0x9e, 0x31, 0x18, 0x3d, 0x0c, 0x33, 0x36, 0xe8, 0xcd, 0xd5, 0x51, 0x7f, 0x55, 0xd2, 0x63, 0x08, + 0x57, 0xf5, 0xdb, 0xf5, 0xe8, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x41, 0xda, 0x1f, 0xc7, 0xd1, + 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -457,6 +468,13 @@ func (m *GetTxWithProofResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l + if len(m.TxBytes) > 0 { + i -= len(m.TxBytes) + copy(dAtA[i:], m.TxBytes) + i = encodeVarintQuery(dAtA, i, uint64(len(m.TxBytes))) + i-- + dAtA[i] = 0x2a + } if m.Header != nil { { size, err := m.Header.MarshalToSizedBuffer(dAtA[:i]) @@ -577,6 +595,10 @@ func (m *GetTxWithProofResponse) Size() (n int) { l = m.Header.Size() n += 1 + l + sovQuery(uint64(l)) } + l = len(m.TxBytes) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -997,6 +1019,40 @@ func (m *GetTxWithProofResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TxBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TxBytes = append(m.TxBytes[:0], dAtA[iNdEx:postIndex]...) + if m.TxBytes == nil { + m.TxBytes = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/interchainstaking/keeper/address_map_test.go b/x/interchainstaking/keeper/address_map_test.go index e0f7f9f5a..fa0288b06 100644 --- a/x/interchainstaking/keeper/address_map_test.go +++ b/x/interchainstaking/keeper/address_map_test.go @@ -1,96 +1,92 @@ package keeper_test -import "github.com/ingenuity-build/quicksilver/utils" +import ( + "github.com/ingenuity-build/quicksilver/utils/randomutils" +) const ( testChainID = "test-1" ) -func (s *KeeperTestSuite) TestKeeper_RemoteAddressStore() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_RemoteAddressStore() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() - localAddress, err := utils.GenerateRandomBytes(28) - s.Require().NoError(err) - remoteAddress, err := utils.GenerateRandomBytes(40) - s.Require().NoError(err) + localAddress := randomutils.GenerateRandomBytes(28) + remoteAddress := randomutils.GenerateRandomBytes(40) - s.Run("not found", func() { + suite.Run("not found", func() { _, found := icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) }) - s.Run("set", func() { + suite.Run("set", func() { icsKeeper.SetRemoteAddressMap(ctx, localAddress, remoteAddress, testChainID) }) - s.Run("found", func() { + suite.Run("found", func() { addr, found := icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) - s.Require().True(found) - s.Require().Equal(remoteAddress, addr) + suite.Require().True(found) + suite.Require().Equal(remoteAddress, addr) }) } -func (s *KeeperTestSuite) TestKeeper_LocalAddressStore() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_LocalAddressStore() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() - localAddress, err := utils.GenerateRandomBytes(28) - s.Require().NoError(err) - remoteAddress, err := utils.GenerateRandomBytes(40) - s.Require().NoError(err) + localAddress := randomutils.GenerateRandomBytes(28) + remoteAddress := randomutils.GenerateRandomBytes(40) - s.Run("not found", func() { + suite.Run("not found", func() { _, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) }) - s.Run("set", func() { + suite.Run("set", func() { icsKeeper.SetLocalAddressMap(ctx, localAddress, remoteAddress, testChainID) }) - s.Run("found", func() { + suite.Run("found", func() { addr, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().True(found) - s.Require().Equal(localAddress, addr) + suite.Require().True(found) + suite.Require().Equal(localAddress, addr) }) } -func (s *KeeperTestSuite) TestKeeper_AddressMapPair() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestKeeper_AddressMapPair() { + suite.SetupTest() + suite.setupTestZones() - icsKeeper := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper - ctx := s.chainA.GetContext() + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() - localAddress, err := utils.GenerateRandomBytes(28) - s.Require().NoError(err) - remoteAddress, err := utils.GenerateRandomBytes(40) - s.Require().NoError(err) + localAddress := randomutils.GenerateRandomBytes(28) + remoteAddress := randomutils.GenerateRandomBytes(40) - s.Run("not found", func() { + suite.Run("not found", func() { _, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) _, found = icsKeeper.GetRemoteAddressMap(ctx, remoteAddress, testChainID) - s.Require().False(found) + suite.Require().False(found) }) - s.Run("set", func() { + suite.Run("set", func() { icsKeeper.SetAddressMapPair(ctx, localAddress, remoteAddress, testChainID) }) - s.Run("found", func() { + suite.Run("found", func() { addr, found := icsKeeper.GetLocalAddressMap(ctx, remoteAddress, testChainID) - s.Require().True(found) - s.Require().Equal(localAddress, addr) + suite.Require().True(found) + suite.Require().Equal(localAddress, addr) addr, found = icsKeeper.GetRemoteAddressMap(ctx, localAddress, testChainID) - s.Require().True(found) - s.Require().Equal(remoteAddress, addr) + suite.Require().True(found) + suite.Require().Equal(remoteAddress, addr) }) } diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index c3df0e287..616006a54 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -2,23 +2,30 @@ package keeper import ( "bytes" + "encoding/hex" "errors" "fmt" + "strings" "time" sdkioerrors "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/tx" + "google.golang.org/protobuf/encoding/protowire" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" + "github.com/tendermint/tendermint/crypto/tmhash" tmtypes "github.com/tendermint/tendermint/types" "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -156,11 +163,11 @@ func DelegationCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes. if err != nil { return err } - validatorAddress, err := bech32.ConvertAndEncode(zone.GetValoperPrefix(), validator) + validatorAddress, err := addressutils.EncodeAddressToBech32(zone.GetValoperPrefix(), validator) if err != nil { return err } - delegatorAddress, err := bech32.ConvertAndEncode(zone.GetAccountPrefix(), delegator) + delegatorAddress, err := addressutils.EncodeAddressToBech32(zone.GetAccountPrefix(), delegator) if err != nil { return err } @@ -173,7 +180,7 @@ func DelegationCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes. } return nil } - valAddrBytes, err := utils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) + valAddrBytes, err := addressutils.ValAddressFromBech32(delegation.ValidatorAddress, zone.GetValoperPrefix()) if err != nil { return err } @@ -419,18 +426,37 @@ func DepositTxCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes.Q return err } - _, found = k.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, res.GetTxResponse().TxHash)) + // check tx is valid for hash. + hash := tmhash.Sum(res.Proof.Data) + hashStr := hex.EncodeToString(hash) + + queryRequest := tx.GetTxRequest{} + err = k.cdc.Unmarshal(query.Request, &queryRequest) + if err != nil { + return err + } + + // check hash matches query + if !strings.EqualFold(hashStr, queryRequest.Hash) { + return fmt.Errorf("invalid tx for query - expected %s, got %s", queryRequest.Hash, hashStr) + } + + _, found = k.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hashStr)) if found { - k.Logger(ctx).Debug("Found previously handled tx. Ignoring.", "txhash", res.GetTxResponse().TxHash) + k.Logger(ctx).Info("Found previously handled tx. Ignoring.", "txhash", hashStr) return nil } - err = k.CheckTMHeaderForZone(ctx, &zone, res) + txn, err := txDecoder(k.cdc)(res.Proof.Data) if err != nil { - return fmt.Errorf("unable to verify proof: %w", err) + return err } - return k.HandleReceiptForTransaction(ctx, res.GetTxResponse(), res.GetTx(), &zone) + txtx, ok := txn.(*tx.Tx) + if !ok { + return errors.New("cannot assert type of tx") + } + return k.HandleReceiptTransaction(ctx, txtx, hashStr, zone) } // AccountBalanceCallback is a callback handler for Balance queries. @@ -468,7 +494,7 @@ func AccountBalanceCallback(k *Keeper, ctx sdk.Context, args []byte, query icqty return err } - address, err := bech32.ConvertAndEncode(zone.AccountPrefix, accAddr) + address, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, accAddr) if err != nil { return err } @@ -510,7 +536,7 @@ func DelegationAccountBalanceCallback(k *Keeper, ctx sdk.Context, args []byte, q k.Logger(ctx).Debug("invalid coin for zone", "zone", zone.ChainId, "err", err) return err } - address, err := bech32.ConvertAndEncode(zone.AccountPrefix, accAddr) + address, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, accAddr) if err != nil { return err } @@ -567,3 +593,113 @@ func AllBalancesCallback(k *Keeper, ctx sdk.Context, args []byte, query icqtypes return k.SetAccountBalance(ctx, zone, balanceQuery.Address, args) } + +// txDecoder. +func txDecoder(cdc codec.Codec) sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + // Make sure txBytes follow ADR-027. + err := rejectNonADR027TxRaw(txBytes) + if err != nil { + return nil, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + var raw tx.TxRaw + + err = cdc.Unmarshal(txBytes, &raw) + if err != nil { + return nil, err + } + + var body tx.TxBody + + err = cdc.Unmarshal(raw.BodyBytes, &body) + if err != nil { + return nil, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + var authInfo tx.AuthInfo + + err = cdc.Unmarshal(raw.AuthInfoBytes, &authInfo) + if err != nil { + return nil, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, err.Error()) + } + + return &tx.Tx{ + Body: &body, + AuthInfo: &authInfo, + Signatures: raw.Signatures, + }, nil + } +} + +func rejectNonADR027TxRaw(txBytes []byte) error { + // Make sure all fields are ordered in ascending order with this variable. + prevTagNum := protowire.Number(0) + + for len(txBytes) > 0 { + tagNum, wireType, m := protowire.ConsumeTag(txBytes) + if m < 0 { + return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) + } + // TxRaw only has bytes fields. + if wireType != protowire.BytesType { + return fmt.Errorf("expected %d wire type, got %d", protowire.BytesType, wireType) + } + // Make sure fields are ordered in ascending order. + if tagNum < prevTagNum { + return fmt.Errorf("txRaw must follow ADR-027, got tagNum %d after tagNum %d", tagNum, prevTagNum) + } + prevTagNum = tagNum + + // All 3 fields of TxRaw have wireType == 2, so their next component + // is a varint, so we can safely call ConsumeVarint here. + // Byte structure: + // Inner fields are verified in `DefaultTxDecoder` + lengthPrefix, m := protowire.ConsumeVarint(txBytes[m:]) + if m < 0 { + return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) + } + // We make sure that this varint is as short as possible. + n := varintMinLength(lengthPrefix) + if n != m { + return fmt.Errorf("length prefix varint for tagNum %d is not as short as possible, read %d, only need %d", tagNum, m, n) + } + + // Skip over the bytes that store fieldNumber and wireType bytes. + _, _, m = protowire.ConsumeField(txBytes) + if m < 0 { + return fmt.Errorf("invalid length; %w", protowire.ParseError(m)) + } + txBytes = txBytes[m:] + } + + return nil +} + +// varintMinLength returns the minimum number of bytes necessary to encode an +// uint using varint encoding. +func varintMinLength(n uint64) int { + switch { + // Note: 1<2%; cap at 2% icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.NewInt(500)) @@ -562,17 +563,17 @@ func (s *KeeperTestSuite) TestUpdateRedemptionRate() { icsKeeper.SetDelegation(ctx, &zone, delegationA) icsKeeper.SetDelegation(ctx, &zone, delegationB) icsKeeper.SetDelegation(ctx, &zone, delegationC) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // should be capped at 2% increase. (1.01*1.02 == 1.0302) - s.Require().Equal(sdk.NewDecWithPrec(10302, 4), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(10302, 4), zone.RedemptionRate) // add nothing, still cap at 2% icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.ZeroInt()) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) // should be capped at 2% increase. (1.01*1.02*1.02 == 1.050804) - s.Require().Equal(sdk.NewDecWithPrec(1050804, 6), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(1050804, 6), zone.RedemptionRate) delegationA.Amount.Amount = delegationA.Amount.Amount.SubRaw(500) delegationB.Amount.Amount = delegationB.Amount.Amount.SubRaw(500) @@ -583,23 +584,23 @@ func (s *KeeperTestSuite) TestUpdateRedemptionRate() { // remove > 5%, cap at -5% icsKeeper.UpdateRedemptionRate(ctx, &zone, sdk.ZeroInt()) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(9982638, 7), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(9982638, 7), zone.RedemptionRate) } -func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { + suite.SetupTest() + suite.setupTestZones() - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetAllValidators(s.chainB.GetContext()) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetAllValidators(suite.chainB.GetContext()) delegationA := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[0].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationB := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[1].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} delegationC := icstypes.Delegation{DelegationAddress: zone.DelegationAddress.Address, ValidatorAddress: vals[2].OperatorAddress, Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))} @@ -609,15 +610,15 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationC) err := quicksilver.MintKeeper.MintCoins(ctx, sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewInt(3000)))) - s.Require().NoError(err) + suite.Require().NoError(err) // no change! - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.OneDec(), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.OneDec(), zone.RedemptionRate) // add 1% delegationA.Amount.Amount = delegationA.Amount.Amount.AddRaw(10) @@ -628,9 +629,9 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationC) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(101, 2), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(101, 2), zone.RedemptionRate) // add >2%; no cap delegationA.Amount.Amount = delegationA.Amount.Amount.AddRaw(166) @@ -641,15 +642,15 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationC) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) // add nothing, no change icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + suite.Require().Equal(sdk.NewDecWithPrec(1176666666666666667, 18), zone.RedemptionRate) delegationA.Amount.Amount = delegationA.Amount.Amount.SubRaw(500) delegationB.Amount.Amount = delegationB.Amount.Amount.SubRaw(500) @@ -658,8 +659,8 @@ func (s *KeeperTestSuite) TestOverrideRedemptionRateNoCap() { icsKeeper.SetDelegation(ctx, &zone, delegationB) icsKeeper.SetDelegation(ctx, &zone, delegationC) icsKeeper.OverrideRedemptionRateNoCap(ctx, &zone) - zone, found = icsKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found = icsKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - s.Require().Equal(sdk.NewDecWithPrec(676666666666666667, 18), zone.RedemptionRate) + suite.Require().Equal(sdk.NewDecWithPrec(676666666666666667, 18), zone.RedemptionRate) } diff --git a/x/interchainstaking/keeper/msg_server.go b/x/interchainstaking/keeper/msg_server.go index 9d679dcee..38e4426b0 100644 --- a/x/interchainstaking/keeper/msg_server.go +++ b/x/interchainstaking/keeper/msg_server.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -55,7 +55,7 @@ func (k msgServer) RequestRedemption(goCtx context.Context, msg *types.MsgReques } // does destination address match the prefix registered against the zone? - if _, err := utils.AccAddressFromBech32(msg.DestinationAddress, zone.AccountPrefix); err != nil { + if _, err := addressutils.AccAddressFromBech32(msg.DestinationAddress, zone.AccountPrefix); err != nil { return nil, fmt.Errorf("destination address %s does not match expected prefix %s [%w]", msg.DestinationAddress, zone.AccountPrefix, err) } diff --git a/x/interchainstaking/keeper/msg_server_test.go b/x/interchainstaking/keeper/msg_server_test.go index 42d49121b..18d4c34c0 100644 --- a/x/interchainstaking/keeper/msg_server_test.go +++ b/x/interchainstaking/keeper/msg_server_test.go @@ -6,18 +6,17 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestRequestRedemption() { +func (suite *KeeperTestSuite) TestRequestRedemption() { var msg icstypes.MsgRequestRedemption - testAccount, err := utils.AccAddressFromBech32(testAddress, "") - s.Require().NoError(err) + testAccount, err := addressutils.AccAddressFromBech32(testAddress, "") + suite.Require().NoError(err) tests := []struct { name string @@ -28,8 +27,8 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, @@ -42,18 +41,18 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim (discounted)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.RedemptionRate = sdk.MustNewDecFromStr("0.95") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -61,19 +60,19 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim (interest)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.LastRedemptionRate = sdk.MustNewDecFromStr("1.05") zone.RedemptionRate = sdk.MustNewDecFromStr("1.1") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -81,19 +80,19 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - full claim (interest)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.LastRedemptionRate = sdk.MustNewDecFromStr("1.1") zone.RedemptionRate = sdk.MustNewDecFromStr("1.05") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -101,8 +100,8 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - partial claim", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, @@ -115,18 +114,18 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - partial claim (discounted)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.RedemptionRate = sdk.MustNewDecFromStr("0.99999") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -134,19 +133,19 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "valid - partial claim (interest)", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.LastRedemptionRate = sdk.MustNewDecFromStr("1.049999") zone.RedemptionRate = sdk.MustNewDecFromStr("1.099999") - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "", "", @@ -154,18 +153,18 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "invalid - unbonding not enabled for zone", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(5000000)), DestinationAddress: addr, FromAddress: testAddress, } - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) zone.UnbondingEnabled = false - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone) }, "unbonding currently disabled for zone testchain2", "unbonding currently disabled for zone testchain2", @@ -173,8 +172,8 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "invalid - wrong denom", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uatom", sdk.NewInt(10000000)), DestinationAddress: addr, @@ -187,8 +186,8 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "invalid - insufficient funds", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(1000000000)), DestinationAddress: addr, @@ -201,8 +200,8 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "invalid - bad prefix", func() { - addr, err := bech32.ConvertAndEncode("bob", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("bob", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.OneInt()), DestinationAddress: addr, @@ -215,8 +214,8 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "invalid - bad from address", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.OneInt()), DestinationAddress: addr, @@ -229,23 +228,23 @@ func (s *KeeperTestSuite) TestRequestRedemption() { { "invalid - too many locked tokens", func() { - addr, err := bech32.ConvertAndEncode("cosmos", utils.GenerateAccAddressForTest()) - s.Require().NoError(err) + addr, err := addressutils.EncodeAddressToBech32("cosmos", addressutils.GenerateAccAddressForTest()) + suite.Require().NoError(err) msg = icstypes.MsgRequestRedemption{ Value: sdk.NewCoin("uqatom", sdk.NewInt(10000000)), DestinationAddress: addr, FromAddress: testAddress, } - ctx := s.chainA.GetContext() - zoneVals := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, s.chainB.ChainID) - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetRedelegationRecord(ctx, icstypes.RedelegationRecord{ - ChainId: s.chainB.ChainID, + ctx := suite.chainA.GetContext() + zoneVals := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, suite.chainB.ChainID) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetRedelegationRecord(ctx, icstypes.RedelegationRecord{ + ChainId: suite.chainB.ChainID, EpochNumber: 1, Source: zoneVals[0], Destination: zoneVals[1], Amount: 3000000, - CompletionTime: s.chainA.GetContext().BlockTime().Add(time.Hour), + CompletionTime: suite.chainA.GetContext().BlockTime().Add(time.Hour), }) }, "", @@ -257,68 +256,68 @@ func (s *KeeperTestSuite) TestRequestRedemption() { tt := tt // run tests with LSM disabled. - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - params := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetParams(ctx) + params := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetParams(ctx) params.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetParams(ctx, params) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetParams(ctx, params) - err := s.GetQuicksilverApp(s.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) - err = s.GetQuicksilverApp(s.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) + err := suite.GetQuicksilverApp(suite.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) + err = suite.GetQuicksilverApp(suite.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) // disable LSM - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) zone.LiquidityModule = false zone.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) tt.malleate() - msgSrv := icskeeper.NewMsgServerImpl(s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper) - res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(s.chainA.GetContext()), &msg) + msgSrv := icskeeper.NewMsgServerImpl(suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(suite.chainA.GetContext()), &msg) if tt.expectErr != "" { - s.Require().ErrorContains(err, tt.expectErr) - s.Require().Nil(res) - s.T().Logf("Error: %v", err) + suite.Require().ErrorContains(err, tt.expectErr) + suite.Require().Nil(res) + suite.T().Logf("Error: %v", err) } else { - s.Require().NoError(err) - s.Require().NotNil(res) + suite.Require().NoError(err) + suite.Require().NotNil(res) } }) // run tests with LSM enabled. tt.name += "_LSM_enabled" - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() - params := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetParams(ctx) + params := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetParams(ctx) params.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetParams(ctx, params) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetParams(ctx, params) - err := s.GetQuicksilverApp(s.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) - err = s.GetQuicksilverApp(s.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) - s.Require().NoError(err) + err := suite.GetQuicksilverApp(suite.chainA).BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) + err = suite.GetQuicksilverApp(suite.chainA).BankKeeper.SendCoinsFromModuleToAccount(ctx, icstypes.ModuleName, testAccount, sdk.NewCoins(sdk.NewCoin("uqatom", math.NewInt(10000000)))) + suite.Require().NoError(err) // enable LSM - zone, found := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) zone.LiquidityModule = true zone.UnbondingEnabled = true - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(ctx, &zone) - validators := s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, s.chainB.ChainID) + validators := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetValidatorAddresses(ctx, suite.chainB.ChainID) for _, delegation := range func(zone icstypes.Zone) []icstypes.Delegation { out := make([]icstypes.Delegation, 0) for _, valoper := range validators { @@ -326,43 +325,43 @@ func (s *KeeperTestSuite) TestRequestRedemption() { } return out }(zone) { - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetDelegation(ctx, &zone, delegation) } tt.malleate() - msgSrv := icskeeper.NewMsgServerImpl(s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper) - res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(s.chainA.GetContext()), &msg) + msgSrv := icskeeper.NewMsgServerImpl(suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + res, err := msgSrv.RequestRedemption(sdk.WrapSDKContext(suite.chainA.GetContext()), &msg) if tt.expectErrLsm != "" { - s.Require().Errorf(err, tt.expectErrLsm) - s.Require().Nil(res) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.expectErrLsm) + suite.Require().Nil(res) + suite.T().Logf("Error: %v", err) } else { - s.Require().NoError(err) - s.Require().NotNil(res) + suite.Require().NoError(err) + suite.Require().NotNil(res) } }) } } -func (s *KeeperTestSuite) TestSignalIntent() { +func (suite *KeeperTestSuite) TestSignalIntent() { tests := []struct { name string - malleate func(s *KeeperTestSuite) *icstypes.MsgSignalIntent + malleate func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent expected []sdk.Dec failsValidations bool expectErr bool }{ { "invalid - weight sum < 1", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("0.3%s", val1.String()), FromAddress: testAddress, } @@ -373,12 +372,12 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "invalid - weight sum > 1", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("3.0%s", val1.String()), FromAddress: testAddress, } @@ -389,12 +388,12 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "invalid - chain id", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainA.ChainID, + ChainId: suite.chainA.ChainID, Intents: fmt.Sprintf("1.0%s", val1.String()), FromAddress: testAddress, } @@ -405,12 +404,12 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "valid - single weight", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("1.0%s", val1.String()), FromAddress: testAddress, } @@ -421,16 +420,16 @@ func (s *KeeperTestSuite) TestSignalIntent() { }, { "valid - multi weight", - func(s *KeeperTestSuite) *icstypes.MsgSignalIntent { - val1, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[0].Address.String()) - s.Require().NoError(err) - val2, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[1].Address.String()) - s.Require().NoError(err) - val3, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[2].Address.String()) - s.Require().NoError(err) + func(suite *KeeperTestSuite) *icstypes.MsgSignalIntent { + val1, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[0].Address.String()) + suite.Require().NoError(err) + val2, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[1].Address.String()) + suite.Require().NoError(err) + val3, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[2].Address.String()) + suite.Require().NoError(err) return &icstypes.MsgSignalIntent{ - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Intents: fmt.Sprintf("0.5%s,0.2%s,0.3%s", val1.String(), val2.String(), val3.String()), FromAddress: testAddress, } @@ -448,47 +447,47 @@ func (s *KeeperTestSuite) TestSignalIntent() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() - s.setupTestZones() + suite.Run(tt.name, func() { + suite.SetupTest() + suite.setupTestZones() - msg := tt.malleate(s) + msg := tt.malleate(suite) // validateBasic not explicitly tested here - but we don't call it inside msgSrv.SignalIntent // so call here to make sure out tests are sane. err := msg.ValidateBasic() if tt.failsValidations { - s.Require().Error(err) + suite.Require().Error(err) return } - s.Require().NoError(err) + suite.Require().NoError(err) - msgSrv := icskeeper.NewMsgServerImpl(s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper) - res, err := msgSrv.SignalIntent(sdk.WrapSDKContext(s.chainA.GetContext()), msg) + msgSrv := icskeeper.NewMsgServerImpl(suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper) + res, err := msgSrv.SignalIntent(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) if tt.expectErr { - s.Require().Error(err) - s.Require().Nil(res) + suite.Require().Error(err) + suite.Require().Nil(res) } else { - s.Require().NoError(err) - s.Require().NotNil(res) + suite.Require().NoError(err) + suite.Require().NotNil(res) } - quicksilver := s.GetQuicksilverApp(s.chainA) + quicksilver := suite.GetQuicksilverApp(suite.chainA) icsKeeper := quicksilver.InterchainstakingKeeper - zone, found := icsKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := icsKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) - intent, found := icsKeeper.GetDelegatorIntent(s.chainA.GetContext(), &zone, testAddress, false) - s.Require().True(found) + intent, found := icsKeeper.GetDelegatorIntent(suite.chainA.GetContext(), &zone, testAddress, false) + suite.Require().True(found) intents := intent.GetIntents() for idx, weight := range tt.expected { - val, err := sdk.ValAddressFromHex(s.chainB.Vals.Validators[idx].Address.String()) - s.Require().NoError(err) + val, err := sdk.ValAddressFromHex(suite.chainB.Vals.Validators[idx].Address.String()) + suite.Require().NoError(err) valIntent, found := intents.GetForValoper(val.String()) - s.Require().True(found) + suite.Require().True(found) - s.Require().Equal(weight, valIntent.Weight) + suite.Require().Equal(weight, valIntent.Weight) } }) } diff --git a/x/interchainstaking/keeper/proposal_handler.go b/x/interchainstaking/keeper/proposal_handler.go index 8f2127ac7..77e63455d 100644 --- a/x/interchainstaking/keeper/proposal_handler.go +++ b/x/interchainstaking/keeper/proposal_handler.go @@ -64,6 +64,7 @@ func (k *Keeper) HandleRegisterZoneProposal(ctx sdk.Context, p *types.RegisterZo Decimals: p.Decimals, UnbondingPeriod: int64(tmClientState.UnbondingPeriod), MessagesPerTx: p.MessagesPerTx, + Is_118: p.Is_118, } k.SetZone(ctx, zone) diff --git a/x/interchainstaking/keeper/receipt.go b/x/interchainstaking/keeper/receipt.go index da69242d5..5366ebcfc 100644 --- a/x/interchainstaking/keeper/receipt.go +++ b/x/interchainstaking/keeper/receipt.go @@ -8,7 +8,6 @@ import ( sdkioerrors "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/tx" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" @@ -16,6 +15,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" host "github.com/cosmos/ibc-go/v5/modules/core/24-host" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -25,51 +25,51 @@ const ( ICATimeout = time.Hour * 6 ) -func (k *Keeper) HandleReceiptForTransaction(ctx sdk.Context, txr *sdk.TxResponse, txn *tx.Tx, zone *types.Zone) error { - k.Logger(ctx).Info("deposit receipt.", "ischeck", ctx.IsCheckTx(), "isrecheck", ctx.IsReCheckTx()) - hash := txr.TxHash +func (k *Keeper) HandleReceiptTransaction(ctx sdk.Context, txn *tx.Tx, hash string, zone types.Zone) error { + k.Logger(ctx).Info("Deposit receipt.", "ischeck", ctx.IsCheckTx(), "isrecheck", ctx.IsReCheckTx()) memo := txn.Body.Memo senderAddress := Unset assets := sdk.Coins{} - for _, event := range txr.Events { - if event.Type == types.TransferPort { - attrs := types.AttributesToMap(event.Attributes) - sender := attrs["sender"] - amount := attrs["amount"] - if attrs["recipient"] == zone.DepositAddress.GetAddress() { // negate case where sender sends to multiple addresses in one tx - if senderAddress == Unset { - senderAddress = sender - } - - if sender != senderAddress { - k.Logger(ctx).Error("sender mismatch", "expected", senderAddress, "received", sender) - return fmt.Errorf("sender mismatch: expected %q, got %q", senderAddress, sender) - } - - k.Logger(ctx).Info("deposit receipt", "deposit_address", zone.DepositAddress.GetAddress(), "sender", sender, "amount", amount) - thisCoins, err := sdk.ParseCoinsNormalized(amount) - if err != nil { - k.Logger(ctx).Error("unable to parse coin", "string", amount) - } - assets = assets.Add(thisCoins...) + for _, msg := range txn.GetMsgs() { + msgSend, ok := msg.(*bankTypes.MsgSend) + if !ok { + k.Logger(ctx).Error("got message that wasn't MsgSend!") + continue + } + sender := msgSend.FromAddress + amount := msgSend.Amount + + if msgSend.ToAddress == zone.DepositAddress.GetAddress() { // negate case where sender sends to multiple addresses in one tx + if senderAddress == Unset { + senderAddress = sender + } + + if sender != senderAddress { + k.Logger(ctx).Error("sender mismatch", "expected", senderAddress, "received", sender) + k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again + return nil } + + k.Logger(ctx).Info("Deposit receipt", "deposit_address", zone.DepositAddress.GetAddress(), "sender", sender, "amount", amount) + + assets = assets.Add(amount...) } + } if senderAddress == Unset { k.Logger(ctx).Error("no sender found. Ignoring.") - return fmt.Errorf("no sender found. Ignoring") + k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again + return nil } - - // sdk.AccAddressFromBech32 doesn't work here as it expects the local HRP - _, addressBytes, err := bech32.DecodeAndConvert(senderAddress) + senderAccAddress, err := addressutils.AccAddressFromBech32(senderAddress, zone.GetAccountPrefix()) if err != nil { - k.Logger(ctx).Error("unable to decode sender address. Ignoring.", "senderAddress", senderAddress) - return fmt.Errorf("unable to decode sender address. Ignoring. senderAddress=%q", senderAddress) + k.Logger(ctx).Error("unable to decode sender address. Ignoring.", "senderAddress", senderAddress, "error", err) + k.NilReceipt(ctx, &zone, hash) // nil receipt will stop this hash being submitted again + return nil } - var senderAccAddress sdk.AccAddress = addressBytes if err := zone.ValidateCoinsForZone(assets, k.GetValidatorAddresses(ctx, zone.ChainId)); err != nil { // we expect this to trigger if the validatorset has changed recently (i.e. we haven't seen the validator before. @@ -99,21 +99,21 @@ func (k *Keeper) HandleReceiptForTransaction(ctx sdk.Context, txr *sdk.TxRespons } // update state - if err := k.UpdateDelegatorIntent(ctx, senderAccAddress, zone, assets, memoIntent); err != nil { + if err := k.UpdateDelegatorIntent(ctx, senderAccAddress, &zone, assets, memoIntent); err != nil { k.Logger(ctx).Error("unable to update intent. Ignoring.", "senderAddress", senderAddress, "zone", zone.ChainId, "err", err.Error()) return fmt.Errorf("unable to update intent. Ignoring. senderAddress=%q zone=%q err: %w", senderAddress, zone.ChainId, err) } - if err := k.MintAndSendQAsset(ctx, senderAccAddress, senderAddress, zone, assets, memoRTS, mappedAddress); err != nil { + if err := k.MintAndSendQAsset(ctx, senderAccAddress, senderAddress, &zone, assets, memoRTS, mappedAddress); err != nil { k.Logger(ctx).Error("unable to mint QAsset. Ignoring.", "senderAddress", senderAddress, "zone", zone.ChainId, "err", err) return fmt.Errorf("unable to mint QAsset. Ignoring. senderAddress=%q zone=%q err: %w", senderAddress, zone.ChainId, err) } - if err := k.TransferToDelegate(ctx, zone, assets, hash); err != nil { + if err := k.TransferToDelegate(ctx, &zone, assets, hash); err != nil { k.Logger(ctx).Error("unable to transfer to delegate. Ignoring.", "senderAddress", senderAddress, "zone", zone.ChainId, "err", err) return fmt.Errorf("unable to transfer to delegate. Ignoring. senderAddress=%q zone=%q err: %w", senderAddress, zone.ChainId, err) } // create receipt - receipt := k.NewReceipt(ctx, zone, senderAddress, hash, assets) + receipt := k.NewReceipt(ctx, &zone, senderAddress, hash, assets) k.SetReceipt(ctx, *receipt) return nil @@ -294,6 +294,12 @@ func (k *Keeper) SubmitTx(ctx sdk.Context, msgs []sdk.Msg, account *types.ICAAcc // --------------------------------------------------------------- +func (k Keeper) NilReceipt(ctx sdk.Context, zone *types.Zone, txhash string) { + t := ctx.BlockTime() + r := types.Receipt{ChainId: zone.ChainId, Sender: "", Txhash: txhash, Amount: sdk.Coins{}, FirstSeen: &t, Completed: &t} + k.SetReceipt(ctx, r) +} + func (k Keeper) NewReceipt(ctx sdk.Context, zone *types.Zone, sender, txhash string, amount sdk.Coins) *types.Receipt { t := ctx.BlockTime() return &types.Receipt{ChainId: zone.ChainId, Sender: sender, Txhash: txhash, Amount: amount, FirstSeen: &t} @@ -374,7 +380,7 @@ func (k *Keeper) IterateZoneReceipts(ctx sdk.Context, zone *types.Zone, fn func( func (k *Keeper) UserZoneReceipts(ctx sdk.Context, zone *types.Zone, addr sdk.AccAddress) ([]types.Receipt, error) { receipts := make([]types.Receipt, 0) - bech32Address, err := bech32.ConvertAndEncode(zone.AccountPrefix, addr) + bech32Address, err := addressutils.EncodeAddressToBech32(zone.AccountPrefix, addr) if err != nil { return receipts, err } @@ -399,7 +405,3 @@ func (k *Keeper) SetReceiptsCompleted(ctx sdk.Context, zone *types.Zone, qualify return false }) } - -func GetReceiptKey(chainID, txhash string) string { - return fmt.Sprintf("%s/%s", chainID, txhash) -} diff --git a/x/interchainstaking/keeper/receipt_test.go b/x/interchainstaking/keeper/receipt_test.go new file mode 100644 index 000000000..b43f24cd9 --- /dev/null +++ b/x/interchainstaking/keeper/receipt_test.go @@ -0,0 +1,314 @@ +package keeper_test + +import ( + "time" + + "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ingenuity-build/quicksilver/utils/addressutils" + "github.com/ingenuity-build/quicksilver/utils/randomutils" + "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" +) + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionGood() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := randomutils.GenerateRandomHashAsHex(64) + hash2 := randomutils.GenerateRandomHashAsHex(64) + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + // rr is 1.0 + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + suite.Require().NoError(err) + + after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1000000)), after) + + zone.RedemptionRate = sdk.NewDecWithPrec(12, 1) + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash2, zone) + suite.Require().NoError(err) + + after2 := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1833333)), after2) +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadRecipient() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := randomutils.GenerateRandomHashAsHex(64) + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + // suite.Require().ErrorContains(err, "no sender found. Ignoring") + nilReceipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash)) + suite.Require().True(found) // check nilReceipt is found for hash + suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender + suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount + suite.Require().NoError(err) +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMessageType() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + + msg := stakingtypes.MsgDelegate{DelegatorAddress: fromAddress, ValidatorAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := randomutils.GenerateRandomHashAsHex(64) + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + // suite.Require().ErrorContains(err, "no sender found. Ignoring") + nilReceipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash)) + suite.Require().True(found) // check nilReceipt is found for hash + suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender + suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount + suite.Require().NoError(err) +} + +func (suite *KeeperTestSuite) TestHandleReceiptMixedMessageTypeGood() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + msg2 := stakingtypes.MsgDelegate{DelegatorAddress: fromAddress, ValidatorAddress: zone.DelegationAddress.Address, Amount: sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000))} + anymsg2, err := codectypes.NewAnyWithValue(&msg2) + suite.Require().NoError(err) + + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} + hash := randomutils.GenerateRandomHashAsHex(64) + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + suite.Require().NoError(err) + + after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, math.NewInt(1000000)), after) +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadMixedSender() { // this shouldn't be possibly in theory, but hey! + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + fromAddress2 := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + msg2 := banktypes.MsgSend{FromAddress: fromAddress2, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, math.NewInt(1000000)))} + anymsg2, err := codectypes.NewAnyWithValue(&msg2) + suite.Require().NoError(err) + + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg, anymsg2}}} + hash := randomutils.GenerateRandomHashAsHex(64) + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + // suite.Require().ErrorContains(err, "sender mismatch: expected") + nilReceipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash)) + suite.Require().True(found) // check nilReceipt is found for hash + suite.Require().Equal("", nilReceipt.Sender) // check nilReceipt has empty sender + suite.Require().Nil(nilReceipt.Amount) // check nilReceipt has nil amount + suite.Require().NoError(err) +} + +func (suite *KeeperTestSuite) TestHandleReceiptTransactionBadDenom() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + fromAddress := addressutils.GenerateAddressForTestWithPrefix(zone.AccountPrefix) + + msg := banktypes.MsgSend{FromAddress: fromAddress, ToAddress: zone.DepositAddress.Address, Amount: sdk.NewCoins(sdk.NewCoin("ushit", math.NewInt(1000000)))} + anymsg, err := codectypes.NewAnyWithValue(&msg) + suite.Require().NoError(err) + + transaction := &tx.Tx{Body: &tx.TxBody{Messages: []*codectypes.Any{anymsg}}} + hash := randomutils.GenerateRandomHashAsHex(64) + + before := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), before) + + err = icsKeeper.HandleReceiptTransaction(ctx, transaction, hash, zone) + suite.Require().ErrorContains(err, "unable to validate coins. Ignoring") + + after := suite.GetQuicksilverApp(suite.chainA).BankKeeper.GetSupply(ctx, zone.LocalDenom) + suite.Require().Equal(sdk.NewCoin(zone.LocalDenom, sdk.ZeroInt()), after) +} + +// func (suite *KeeperTestSuite) TestMintQAsset() { +// } + +// test all getters, setters, deleters, iterators. +func (suite *KeeperTestSuite) TestReceiptStore() { + suite.SetupTest() + suite.setupTestZones() + + icsKeeper := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper + ctx := suite.chainA.GetContext() + + // get test zone + zone, found := suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) + + account1 := addressutils.GenerateAccAddressForTest() + account2 := addressutils.GenerateAccAddressForTest() + hash1 := randomutils.GenerateRandomHashAsHex(64) + hash2 := randomutils.GenerateRandomHashAsHex(64) + hash3 := randomutils.GenerateRandomHashAsHex(64) + hash4 := randomutils.GenerateRandomHashAsHex(64) + + zone2 := types.Zone{ChainId: "test-1"} + + suite.Require().Zero(len(icsKeeper.AllReceipts(ctx))) + + receipt1 := icsKeeper.NewReceipt(ctx, &zone, account1.String(), hash1, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100)))) + receipt2 := icsKeeper.NewReceipt(ctx, &zone, account1.String(), hash2, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(200)))) + receipt3 := icsKeeper.NewReceipt(ctx, &zone, account2.String(), hash3, sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(300)))) + receipt4 := icsKeeper.NewReceipt(ctx, &zone2, account2.String(), hash4, sdk.NewCoins(sdk.NewCoin("uosmo", math.NewInt(500)))) + + icsKeeper.SetReceipt(ctx, *receipt1) + icsKeeper.SetReceipt(ctx, *receipt2) + icsKeeper.SetReceipt(ctx, *receipt3) + icsKeeper.SetReceipt(ctx, *receipt4) + + suite.Require().Equal(4, len(icsKeeper.AllReceipts(ctx))) + + count := 0 + coins := sdk.Coins{} + icsKeeper.IterateReceipts(ctx, func(index int64, receiptInfo types.Receipt) (stop bool) { + count++ + coins = coins.Add(receiptInfo.Amount...) + return false + }) + + suite.Require().Equal(4, count) + suite.Require().Equal(600, int(coins.AmountOf("uatom").Int64())) + suite.Require().Equal(500, int(coins.AmountOf("uosmo").Int64())) + + count = 0 + sum := 0 + icsKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) { + count++ + sum += int(receiptInfo.Amount.AmountOf("uatom").Int64()) + return false + }) + + suite.Require().Equal(3, count) + suite.Require().Equal(600, sum) + + count = 0 + sum = 0 + icsKeeper.IterateZoneReceipts(ctx, &zone2, func(index int64, receiptInfo types.Receipt) (stop bool) { + count++ + sum += int(receiptInfo.Amount.AmountOf("uosmo").Int64()) + return false + }) + + suite.Require().Equal(1, count) + suite.Require().Equal(500, sum) + + out, err := icsKeeper.UserZoneReceipts(ctx, &zone, account1) + suite.Require().NoError(err) + suite.Require().Equal(2, len(out)) + + receipt, found := icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash1)) + suite.Require().True(found) + suite.Require().Equal(receipt1, &receipt) + now := ctx.BlockTime().Add(time.Second) + receipt.Completed = &now + icsKeeper.SetReceipt(ctx, receipt) + icsKeeper.DeleteReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash2)) + + out, err = icsKeeper.UserZoneReceipts(ctx, &zone, account1) + suite.Require().NoError(err) + suite.Require().Equal(1, len(out)) + suite.Require().Equal(&now, out[0].Completed) + + icsKeeper.SetReceiptsCompleted(ctx, &zone, now, now) + + receipt, found = icsKeeper.GetReceipt(ctx, types.GetReceiptKey(zone.ChainId, hash3)) + suite.Require().True(found) + + suite.Require().Equal(&now, receipt.Completed) +} diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index 199e289d4..58e563e01 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -3,21 +3,21 @@ package keeper_test import ( "time" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { - quicksilver := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - testValidatorOne := utils.GenerateAccAddressForTestWithPrefix("cosmosvaloper") - testValidatorTwo := utils.GenerateValAddressForTestWithPrefix("cosmosvaloper") + testValidatorOne := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper") + testValidatorTwo := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper") - s.SetupTest() + suite.SetupTest() records := quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(0, len(records)) + suite.Require().Equal(0, len(records)) record := types.RedelegationRecord{ ChainId: "cosmoshub-4", @@ -32,22 +32,22 @@ func (s *KeeperTestSuite) TestRedelegationRecordSetGetIterate() { records = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(1, len(records)) + suite.Require().Equal(1, len(records)) recordFetched, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorTwo, 1) - s.Require().True(found) - s.Require().Equal(record, recordFetched) + suite.Require().True(found) + suite.Require().Equal(record, recordFetched) allRecords := quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(1, len(allRecords)) + suite.Require().Equal(1, len(allRecords)) allCosmosRecords := quicksilver.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "cosmoshub-4") - s.Require().Equal(1, len(allCosmosRecords)) + suite.Require().Equal(1, len(allCosmosRecords)) allOtherChainRecords := quicksilver.InterchainstakingKeeper.ZoneRedelegationRecords(ctx, "elgafar-1") - s.Require().Equal(0, len(allOtherChainRecords)) + suite.Require().Equal(0, len(allOtherChainRecords)) quicksilver.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorTwo, 1) allCosmosRecords = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) - s.Require().Equal(0, len(allCosmosRecords)) + suite.Require().Equal(0, len(allCosmosRecords)) } diff --git a/x/interchainstaking/keeper/redemptions.go b/x/interchainstaking/keeper/redemptions.go index 4302fcc17..60a9aefd1 100644 --- a/x/interchainstaking/keeper/redemptions.go +++ b/x/interchainstaking/keeper/redemptions.go @@ -206,8 +206,6 @@ WITHDRAWAL: allocationsMap[v] = sdk.ZeroInt() if allocationsMap[v].IsZero() { - fmt.Println("valopers len", len(valopers)) - fmt.Println("vidx+1", vidx+1) if len(valopers) > vidx+1 { vidx++ v = valopers[vidx] diff --git a/x/interchainstaking/keeper/validator_test.go b/x/interchainstaking/keeper/validator_test.go index c21f0155a..9302bcea5 100644 --- a/x/interchainstaking/keeper/validator_test.go +++ b/x/interchainstaking/keeper/validator_test.go @@ -4,27 +4,27 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) -func (s *KeeperTestSuite) TestStoreGetDeleteValidator() { - s.Run("validator - store / get / delete", func() { - s.SetupTest() - s.setupTestZones() +func (suite *KeeperTestSuite) TestStoreGetDeleteValidator() { + suite.Run("validator - store / get / delete", func() { + suite.SetupTest() + suite.setupTestZones() - app := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + app := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() - zone, found := app.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := app.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - validator := utils.GenerateValAddressForTest() + validator := addressutils.GenerateValAddressForTest() - valAddrBytes, err := utils.ValAddressFromBech32(validator.String(), zone.GetValoperPrefix()) - s.Require().NoError(err) + valAddrBytes, err := addressutils.ValAddressFromBech32(validator.String(), zone.GetValoperPrefix()) + suite.Require().NoError(err) _, found = app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) - s.Require().False(found) + suite.Require().False(found) count := len(app.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)) @@ -40,15 +40,15 @@ func (s *KeeperTestSuite) TestStoreGetDeleteValidator() { count2 := len(app.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)) - s.Require().Equal(count+1, count2) + suite.Require().Equal(count+1, count2) fetchedValidator, found := app.InterchainstakingKeeper.GetValidator(ctx, zone.ChainId, valAddrBytes) - s.Require().True(found) - s.Require().Equal(newValidator, fetchedValidator) + suite.Require().True(found) + suite.Require().Equal(newValidator, fetchedValidator) app.InterchainstakingKeeper.DeleteValidator(ctx, zone.ChainId, valAddrBytes) count3 := len(app.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)) - s.Require().Equal(count, count3) + suite.Require().Equal(count, count3) }) } diff --git a/x/interchainstaking/keeper/zones_test.go b/x/interchainstaking/keeper/zones_test.go index f18007807..da42e07eb 100644 --- a/x/interchainstaking/keeper/zones_test.go +++ b/x/interchainstaking/keeper/zones_test.go @@ -15,7 +15,7 @@ import ( "golang.org/x/exp/maps" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -75,7 +75,7 @@ func TestKeeperWithZonesRoundTrip(t *testing.T) { indexToZone := make(map[int64]types.Zone, nzones) for i := 0; i < nzones; i++ { chainID := fmt.Sprintf("%s%d", chainIDPrefix, i) - delegationAddr := utils.GenerateAccAddressForTestWithPrefix("cosmos") + delegationAddr := addressutils.GenerateAddressForTestWithPrefix("cosmos") zone := types.Zone{ ConnectionId: "conn-test", ChainId: chainID, diff --git a/x/interchainstaking/types/accounts.go b/x/interchainstaking/types/accounts.go index 086ac62a4..1d3a699d8 100644 --- a/x/interchainstaking/types/accounts.go +++ b/x/interchainstaking/types/accounts.go @@ -4,19 +4,18 @@ import ( "errors" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) func NewICAAccount(addr, portID string) (*ICAAccount, error) { - if _, err := utils.AccAddressFromBech32(addr, ""); err != nil { + if _, err := addressutils.AccAddressFromBech32(addr, ""); err != nil { return nil, err } return &ICAAccount{Address: addr, WithdrawalAddress: addr, Balance: sdk.Coins{}, PortName: portID}, nil } func (a *ICAAccount) SetWithdrawalAddress(addr string) error { - if _, err := utils.AccAddressFromBech32(addr, ""); err != nil { + if _, err := addressutils.AccAddressFromBech32(addr, ""); err != nil { return err } a.WithdrawalAddress = addr diff --git a/x/interchainstaking/types/delegation_test.go b/x/interchainstaking/types/delegation_test.go index 6b6b05742..8c6668a97 100644 --- a/x/interchainstaking/types/delegation_test.go +++ b/x/interchainstaking/types/delegation_test.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -43,9 +43,9 @@ func TestRoundtripDelegationMarshalToUnmarshal(t *testing.T) { } func TestSetForValoper(t *testing.T) { - v1 := utils.GenerateValAddressForTest().String() - v2 := utils.GenerateValAddressForTest().String() - v3 := utils.GenerateValAddressForTest().String() + v1 := addressutils.GenerateValAddressForTest().String() + v2 := addressutils.GenerateValAddressForTest().String() + v3 := addressutils.GenerateValAddressForTest().String() intents := types.ValidatorIntents{ {ValoperAddress: v1, Weight: sdk.NewDecWithPrec(10, 1)}, @@ -64,10 +64,10 @@ func TestSetForValoper(t *testing.T) { } func TestNormalizeValidatorIntentsDeterminism(t *testing.T) { - v1 := utils.GenerateValAddressForTest().String() - v2 := utils.GenerateValAddressForTest().String() - v3 := utils.GenerateValAddressForTest().String() - v4 := utils.GenerateValAddressForTest().String() + v1 := addressutils.GenerateValAddressForTest().String() + v2 := addressutils.GenerateValAddressForTest().String() + v3 := addressutils.GenerateValAddressForTest().String() + v4 := addressutils.GenerateValAddressForTest().String() cases := []struct { name string @@ -109,10 +109,10 @@ func TestDetermineAllocationsForDelegation(t *testing.T) { // we auto generate the validator addresses in these tests. any dust gets allocated to the first validator in the list // once sorted alphabetically on valoper. - val1 := utils.GenerateValAddressForTest() - val2 := utils.GenerateValAddressForTest() - val3 := utils.GenerateValAddressForTest() - val4 := utils.GenerateValAddressForTest() + val1 := addressutils.GenerateValAddressForTest() + val2 := addressutils.GenerateValAddressForTest() + val3 := addressutils.GenerateValAddressForTest() + val4 := addressutils.GenerateValAddressForTest() tc := []struct { current map[string]sdkmath.Int diff --git a/x/interchainstaking/types/keys.go b/x/interchainstaking/types/keys.go index 0e9e355a1..9e544e580 100644 --- a/x/interchainstaking/types/keys.go +++ b/x/interchainstaking/types/keys.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "fmt" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -122,7 +123,7 @@ func GetPerformanceDelegationsKey(zone *Zone, delAddr sdk.AccAddress) []byte { } func GetReceiptKey(chainID, txhash string) string { - return fmt.Sprintf("%s/%s", chainID, txhash) + return fmt.Sprintf("%s/%s", chainID, strings.ToUpper(txhash)) } // GetRedelegationKey gets the redelegation key. diff --git a/x/interchainstaking/types/messages.pb.go b/x/interchainstaking/types/messages.pb.go index b7412dc03..1c3ffa993 100644 --- a/x/interchainstaking/types/messages.pb.go +++ b/x/interchainstaking/types/messages.pb.go @@ -199,47 +199,47 @@ func init() { } var fileDescriptor_ee484030fa140a82 = []byte{ - // 636 bytes of a gzipped FileDescriptorProto + // 637 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x4f, 0xd4, 0x4e, - 0x1c, 0xc6, 0x77, 0x20, 0x3f, 0xfe, 0x0c, 0xe4, 0x87, 0x16, 0x12, 0x61, 0x43, 0xba, 0xa4, 0x27, - 0xa2, 0xd2, 0xb2, 0xa0, 0xa8, 0x28, 0x44, 0x17, 0x13, 0xc2, 0x81, 0x4b, 0xb9, 0x71, 0xd9, 0xcc, - 0xb6, 0x5f, 0x87, 0x09, 0xed, 0x4c, 0xe9, 0xcc, 0x36, 0x70, 0xf5, 0xe4, 0xd1, 0x44, 0x5f, 0x00, - 0x2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a, 0x8a, 0xf5, + 0xec, 0xa9, 0x5c, 0x9d, 0xa5, 0x42, 0xd0, 0x00, 0x1c, 0x12, 0x31, 0x87, 0x70, 0x2e, 0x14, 0x51, + 0x4c, 0xf0, 0x16, 0xb3, 0x78, 0x6b, 0x83, 0x28, 0x16, 0x91, 0x90, 0x24, 0x28, 0x09, 0xeb, 0x37, + 0xc2, 0x53, 0xdb, 0x92, 0xba, 0x70, 0x90, 0x80, 0x54, 0x2e, 0xf8, 0x10, 0x46, 0x99, 0xa3, 0xf6, + 0x1a, 0xff, 0x97, 0x92, 0x20, 0x81, 0x69, 0x34, 0x87, 0xe6, 0xc7, 0x96, 0x66, 0xec, 0x32, 0x5c, + 0xd6, 0xc4, 0x2e, 0x9b, 0xd8, 0x1b, 0x82, 0xf1, 0xda, 0xe4, 0x69, 0xd3, 0xac, 0x5c, 0x36, 0xcd, + 0xb1, 0x23, 0x12, 0x06, 0xab, 0x56, 0xd6, 0xce, 0x72, 0x0b, 0x58, 0xdb, 0xc2, 0x93, 0x3e, 0x48, + 0xc5, 0x78, 0x1e, 0xb3, 0x4e, 0x7c, 0x3f, 0x06, 0x29, 0xa7, 0x07, 0xe6, 0xd0, 0xfc, 0x68, 0x6d, + 0xfa, 0xeb, 0xc9, 0xc2, 0x54, 0x69, 0xfb, 0xaa, 0x50, 0x76, 0x54, 0xcc, 0x38, 0x75, 0xb5, 0x0e, + 0xa8, 0x54, 0xb4, 0xe7, 0x78, 0xfc, 0x4d, 0x2c, 0xc2, 0xb6, 0xc7, 0xe0, 0x2d, 0x1e, 0x63, 0xd9, + 0xee, 0x72, 0x69, 0x75, 0xe4, 0xdd, 0xb1, 0x59, 0xf9, 0x75, 0x6c, 0x56, 0xac, 0x4f, 0x08, 0x4f, + 0x6c, 0x4b, 0xba, 0xc3, 0x28, 0x27, 0xc1, 0x16, 0x57, 0xc0, 0x95, 0x66, 0xe3, 0x91, 0xfc, 0x77, + 0xaa, 0x33, 0x3f, 0xaf, 0x3b, 0x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, 0xb7, 0x7a, 0x3c, 0xee, 0x35, 0x51, + 0x17, 0xa6, 0xaf, 0xf5, 0x85, 0xb5, 0x9b, 0xac, 0xe7, 0x4d, 0x9e, 0x5a, 0xcb, 0x3d, 0x0e, 0x50, + 0xe6, 0xd1, 0x51, 0xa5, 0xb6, 0x7b, 0x7a, 0x6e, 0xa0, 0xb3, 0x73, 0x03, 0xfd, 0x38, 0x37, 0xd0, + 0xfb, 0x0b, 0xa3, 0x72, 0x76, 0x61, 0x54, 0xbe, 0x5f, 0x18, 0x95, 0xdd, 0x97, 0x94, 0xa9, 0xbd, + 0xa4, 0x61, 0x7b, 0x22, 0x74, 0x18, 0xa7, 0xc0, 0x13, 0xa6, 0x8e, 0x16, 0x1a, 0x09, 0x0b, 0xfc, + 0xae, 0xb3, 0x0e, 0x6f, 0x38, 0x47, 0x1d, 0x45, 0x20, 0x1b, 0x43, 0xf9, 0xe7, 0x75, 0xf9, 0x4f, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x66, 0x57, 0xae, 0x4c, 0x54, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/interchainstaking/types/msgs_test.go b/x/interchainstaking/types/msgs_test.go index ac829eb18..f9bbd8f71 100644 --- a/x/interchainstaking/types/msgs_test.go +++ b/x/interchainstaking/types/msgs_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) @@ -155,8 +155,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Value: sdk.Coin{ Denom: "stake", }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -168,7 +168,7 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Amount: sdkmath.OneInt(), }, DestinationAddress: "", - FromAddress: utils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -179,7 +179,7 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.OneInt(), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), FromAddress: "", }, true, @@ -191,8 +191,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.ZeroInt(), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -203,8 +203,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.NewInt(-1), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, true, }, @@ -215,8 +215,8 @@ func TestMsgRequestRedemption_ValidateBasic(t *testing.T) { Denom: "stake", Amount: sdkmath.OneInt(), }, - DestinationAddress: utils.GenerateAccAddressForTest().String(), - FromAddress: utils.GenerateAccAddressForTest().String(), + DestinationAddress: addressutils.GenerateAccAddressForTest().String(), + FromAddress: addressutils.GenerateAccAddressForTest().String(), }, false, }, diff --git a/x/interchainstaking/types/proposals.pb.go b/x/interchainstaking/types/proposals.pb.go index 9eb93fe61..0d0d90f7a 100644 --- a/x/interchainstaking/types/proposals.pb.go +++ b/x/interchainstaking/types/proposals.pb.go @@ -38,6 +38,7 @@ type RegisterZoneProposal struct { DepositsEnabled bool `protobuf:"varint,11,opt,name=deposits_enabled,json=depositsEnabled,proto3" json:"deposits_enabled,omitempty"` UnbondingEnabled bool `protobuf:"varint,12,opt,name=unbonding_enabled,json=unbondingEnabled,proto3" json:"unbonding_enabled,omitempty"` Decimals int64 `protobuf:"varint,13,opt,name=decimals,proto3" json:"decimals,omitempty"` + Is_118 bool `protobuf:"varint,14,opt,name=is_118,json=is118,proto3" json:"is_118,omitempty"` } func (m *RegisterZoneProposal) Reset() { *m = RegisterZoneProposal{} } @@ -87,6 +88,7 @@ type RegisterZoneProposalWithDeposit struct { DepositsEnabled bool `protobuf:"varint,12,opt,name=deposits_enabled,json=depositsEnabled,proto3" json:"deposits_enabled,omitempty" yaml:"deposits_enabled"` UnbondingEnabled bool `protobuf:"varint,13,opt,name=unbonding_enabled,json=unbondingEnabled,proto3" json:"unbonding_enabled,omitempty" yaml:"deposits_enabled"` Decimals int64 `protobuf:"varint,14,opt,name=decimals,proto3" json:"decimals,omitempty" yaml:"decimals"` + Is_118 bool `protobuf:"varint,15,opt,name=is_118,json=is118,proto3" json:"is_118,omitempty"` } func (m *RegisterZoneProposalWithDeposit) Reset() { *m = RegisterZoneProposalWithDeposit{} } @@ -429,68 +431,69 @@ func init() { } var fileDescriptor_04d034c830a7acfe = []byte{ - // 963 bytes of a gzipped FileDescriptorProto + // 983 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x56, 0x4f, 0x6f, 0xe3, 0xc4, - 0x1b, 0x4e, 0xfa, 0x37, 0x99, 0xfc, 0x69, 0x77, 0x36, 0xfb, 0xfb, 0x79, 0xbb, 0x34, 0x8e, 0xe6, - 0xb0, 0x0a, 0x5a, 0x36, 0xa1, 0x50, 0x01, 0x5a, 0x09, 0x69, 0xc9, 0xfe, 0x81, 0x1e, 0x56, 0xaa, - 0xdc, 0x05, 0xa4, 0x72, 0xb0, 0x1c, 0xfb, 0xc5, 0x19, 0xd5, 0x99, 0xf1, 0x7a, 0xc6, 0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0x9f, 0x50, 0x17, + 0xd3, 0x90, 0x88, 0xd9, 0x83, 0x51, 0x48, 0x3c, 0xa7, 0x9f, 0xbd, 0x95, 0x9f, 0xe5, 0xdc, 0xcb, + 0xc5, 0xcc, 0xc7, 0x7c, 0x54, 0x92, 0xd7, 0xe7, 0xf7, 0xff, 0x08, 0x00, 0x00, 0xff, 0xff, 0x15, + 0x82, 0xe2, 0xcb, 0xc5, 0x0b, 0x00, 0x00, } func (m *RegisterZoneProposal) Marshal() (dAtA []byte, err error) { @@ -513,6 +516,16 @@ func (m *RegisterZoneProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Is_118 { + i-- + if m.Is_118 { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x70 + } if m.Decimals != 0 { i = encodeVarintProposals(dAtA, i, uint64(m.Decimals)) i-- @@ -638,6 +651,16 @@ func (m *RegisterZoneProposalWithDeposit) MarshalToSizedBuffer(dAtA []byte) (int _ = i var l int _ = l + if m.Is_118 { + i-- + if m.Is_118 { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x78 + } if m.Decimals != 0 { i = encodeVarintProposals(dAtA, i, uint64(m.Decimals)) i-- @@ -1134,6 +1157,9 @@ func (m *RegisterZoneProposal) Size() (n int) { if m.Decimals != 0 { n += 1 + sovProposals(uint64(m.Decimals)) } + if m.Is_118 { + n += 2 + } return n } @@ -1192,6 +1218,9 @@ func (m *RegisterZoneProposalWithDeposit) Size() (n int) { if m.Decimals != 0 { n += 1 + sovProposals(uint64(m.Decimals)) } + if m.Is_118 { + n += 2 + } return n } @@ -1711,6 +1740,26 @@ func (m *RegisterZoneProposal) Unmarshal(dAtA []byte) error { break } } + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Is_118", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposals + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Is_118 = bool(v != 0) default: iNdEx = preIndex skippy, err := skipProposals(dAtA[iNdEx:]) @@ -2123,6 +2172,26 @@ func (m *RegisterZoneProposalWithDeposit) Unmarshal(dAtA []byte) error { break } } + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Is_118", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposals + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Is_118 = bool(v != 0) default: iNdEx = preIndex skippy, err := skipProposals(dAtA[iNdEx:]) diff --git a/x/interchainstaking/types/redemptions.go b/x/interchainstaking/types/redemptions.go index 711c2ec5a..573ec5945 100644 --- a/x/interchainstaking/types/redemptions.go +++ b/x/interchainstaking/types/redemptions.go @@ -1,8 +1,6 @@ package types import ( - "fmt" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -34,7 +32,6 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, if !deltas[idx].Weight.IsNegative() { continue } - fmt.Println("trying to remove from overallocated", deltas[idx].ValoperAddress) outWeights[deltas[idx].ValoperAddress] = deltas[idx].Weight.Quo(sdk.NewDecFromInt(sum)).Mul(sdk.NewDecFromInt(overAllocationSplit)).TruncateInt().Abs() if outWeights[deltas[idx].ValoperAddress].GT(availablePerValidator[deltas[idx].ValoperAddress]) { outWeights[deltas[idx].ValoperAddress] = availablePerValidator[deltas[idx].ValoperAddress] @@ -42,7 +39,6 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, } else { availablePerValidator[deltas[idx].ValoperAddress] = availablePerValidator[deltas[idx].ValoperAddress].Sub(outWeights[deltas[idx].ValoperAddress]) } - fmt.Println("removed from overallocated", outWeights[deltas[idx].ValoperAddress]) deltas[idx].Weight = deltas[idx].Weight.Add(sdk.NewDecFromInt(outWeights[deltas[idx].ValoperAddress])) outSum = outSum.Add(outWeights[deltas[idx].ValoperAddress]) diff --git a/x/interchainstaking/types/validator_test.go b/x/interchainstaking/types/validator_test.go index e00e03a20..5b18cc334 100644 --- a/x/interchainstaking/types/validator_test.go +++ b/x/interchainstaking/types/validator_test.go @@ -7,16 +7,16 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) var ( - acc1 = utils.GenerateAccAddressForTest().String() - v1 = utils.GenerateValAddressForTest().String() - v2 = utils.GenerateValAddressForTest().String() - v3 = utils.GenerateValAddressForTest().String() - v4 = utils.GenerateValAddressForTest().String() + acc1 = addressutils.GenerateAccAddressForTest().String() + v1 = addressutils.GenerateValAddressForTest().String() + v2 = addressutils.GenerateValAddressForTest().String() + v3 = addressutils.GenerateValAddressForTest().String() + v4 = addressutils.GenerateValAddressForTest().String() ) func TestSharesToTokens(t *testing.T) { @@ -71,7 +71,7 @@ func TestNormalizeIntentWithEqualIntents(t *testing.T) { } func TestNormalizeIntentWithNonEqualIntents(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.NewDec(5).Quo(sdk.NewDec(50))}, {ValoperAddress: v2, Weight: sdk.NewDec(10).Quo(sdk.NewDec(50))}, {ValoperAddress: v3, Weight: sdk.NewDec(35).Quo(sdk.NewDec(50))}, @@ -84,7 +84,7 @@ func TestNormalizeIntentWithNonEqualIntents(t *testing.T) { } func TestOrdinalizeIntentWithEqualIntents(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v2, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v3, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, @@ -95,7 +95,7 @@ func TestOrdinalizeIntentWithEqualIntents(t *testing.T) { } func TestOrdinalizeIntentWithNonEqualIntents(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.NewDec(5).Quo(sdk.NewDec(50))}, {ValoperAddress: v2, Weight: sdk.NewDec(10).Quo(sdk.NewDec(50))}, {ValoperAddress: v3, Weight: sdk.NewDec(35).Quo(sdk.NewDec(50))}, @@ -108,7 +108,7 @@ func TestOrdinalizeIntentWithNonEqualIntents(t *testing.T) { func TestAddOrdinal(t *testing.T) { di := types.DelegatorIntent{ - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v2, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, @@ -135,7 +135,7 @@ func TestAddOrdinal(t *testing.T) { } func TestAddOrdinalWithNewVal(t *testing.T) { - di := types.DelegatorIntent{Delegator: utils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ + di := types.DelegatorIntent{Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{ {ValoperAddress: v1, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v2, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, {ValoperAddress: v3, Weight: sdk.OneDec().Quo(sdk.NewDec(3))}, diff --git a/x/interchainstaking/types/zones.go b/x/interchainstaking/types/zones.go index 48038e767..aa85099a3 100644 --- a/x/interchainstaking/types/zones.go +++ b/x/interchainstaking/types/zones.go @@ -8,7 +8,7 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/ingenuity-build/quicksilver/utils/addressutils" ) func (z Zone) SupportReturnToSender() bool { return z.ReturnToSender } @@ -207,7 +207,7 @@ func (z *Zone) validatorIntentsFromBytes(coins sdk.Coins, weightBytes []byte) (V index++ address := weightBytes[index : index+20] index += 20 - valAddr, err := bech32.ConvertAndEncode(z.AccountPrefix+"valoper", address) + valAddr, err := addressutils.EncodeAddressToBech32(z.AccountPrefix+"valoper", sdk.ValAddress(address)) if err != nil { return validatorIntents, err } diff --git a/x/interchainstaking/types/zones_test.go b/x/interchainstaking/types/zones_test.go index 21143b920..c808469b6 100644 --- a/x/interchainstaking/types/zones_test.go +++ b/x/interchainstaking/types/zones_test.go @@ -8,25 +8,25 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" ) func TestIsDelegateAddress(t *testing.T) { - acc := utils.GenerateAccAddressForTest() - acc2 := utils.GenerateAccAddressForTest() - bech32 := utils.ConvertAccAddressForTestUsingPrefix(acc, "cosmos") - bech322 := utils.ConvertAccAddressForTestUsingPrefix(acc2, "cosmos") + acc := addressutils.GenerateAccAddressForTest() + acc2 := addressutils.GenerateAccAddressForTest() + bech32 := addressutils.MustEncodeAddressToBech32("cosmos", acc) + bech322 := addressutils.MustEncodeAddressToBech32("cosmos", acc2) zone := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", DelegationAddress: &types.ICAAccount{Address: bech32}, Is_118: true} require.True(t, zone.IsDelegateAddress(bech32)) require.False(t, zone.IsDelegateAddress(bech322)) } func TestGetDelegationAccount(t *testing.T) { - acc := utils.GenerateAccAddressForTest() - bech32 := utils.ConvertAccAddressForTestUsingPrefix(acc, "cosmos") + acc := addressutils.GenerateAccAddressForTest() + bech32 := addressutils.MustEncodeAddressToBech32("cosmos", acc) zone := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", DelegationAddress: &types.ICAAccount{Address: bech32}, Is_118: true} - zone2 := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", Is_118: true} + zone2 := types.Zone{ConnectionId: "connection-0", ChainId: "cosmoshub-4", AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom"} delegateAccount, err := zone.GetDelegationAccount() require.NoError(t, err) @@ -412,7 +412,7 @@ func TestUpdateIntentWithCoins(t *testing.T) { func intentFromDecSlice(in map[string]sdk.Dec) types.DelegatorIntent { out := types.DelegatorIntent{ - Delegator: utils.GenerateAccAddressForTest().String(), + Delegator: addressutils.GenerateAccAddressForTest().String(), Intents: []*types.ValidatorIntent{}, } for addr, weight := range in { diff --git a/x/participationrewards/genesis.go b/x/participationrewards/genesis.go index 72c13b768..988723bf1 100644 --- a/x/participationrewards/genesis.go +++ b/x/participationrewards/genesis.go @@ -13,7 +13,7 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, genState types.GenesisState) k.SetParams(ctx, genState.Params) for _, kpd := range genState.ProtocolData { - k.SetProtocolData(ctx, kpd.Key, kpd.ProtocolData) + k.SetProtocolData(ctx, []byte(kpd.Key), kpd.ProtocolData) } } diff --git a/x/participationrewards/genesis_test.go b/x/participationrewards/genesis_test.go index 54230b993..3613f4131 100644 --- a/x/participationrewards/genesis_test.go +++ b/x/participationrewards/genesis_test.go @@ -33,7 +33,7 @@ func TestParticipationRewardsExportGenesis(t *testing.T) { } protocolData := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], bz) - app.ParticipationRewardsKeeper.SetProtocolData(ctx, fmt.Sprintf("%d", pool.PoolID), protocolData) + app.ParticipationRewardsKeeper.SetProtocolData(ctx, []byte(fmt.Sprintf("%d", pool.PoolID)), protocolData) genesis := participationrewards.ExportGenesis(ctx, app.ParticipationRewardsKeeper) @@ -56,8 +56,8 @@ func TestParticipationRewardsInitGenesis(t *testing.T) { "poolid": 1, "poolname": "atom/osmo", "pooltype": "balancer", - "zones": { - "zone_id": "IBC/zone_denom" + "denoms": { + "ibc/00000000000000000000000000000000": {"denom": "ustake", "chainid": "testzone-1"} } }` diff --git a/x/participationrewards/keeper/callbacks.go b/x/participationrewards/keeper/callbacks.go index 0b025be64..6f7a07efa 100644 --- a/x/participationrewards/keeper/callbacks.go +++ b/x/participationrewards/keeper/callbacks.go @@ -134,7 +134,7 @@ func OsmosisPoolUpdateCallback(ctx sdk.Context, k *Keeper, response []byte, quer if err != nil { return err } - k.SetProtocolData(ctx, fmt.Sprintf("%d", poolID), &data) + k.SetProtocolData(ctx, pool.GenerateKey(), &data) return nil } @@ -193,6 +193,6 @@ func SetEpochBlockCallback(ctx sdk.Context, k *Keeper, args []byte, query icqtyp if err != nil { return err } - k.SetProtocolData(ctx, query.ChainId, &data) + k.SetProtocolData(ctx, connectionData.GenerateKey(), &data) return nil } diff --git a/x/participationrewards/keeper/callbacks_test.go b/x/participationrewards/keeper/callbacks_test.go index 87c1d1dc3..6b42ee1a7 100644 --- a/x/participationrewards/keeper/callbacks_test.go +++ b/x/participationrewards/keeper/callbacks_test.go @@ -15,15 +15,15 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { - prk := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { + prk := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper + ctx := suite.chainA.GetContext() osm := &keeper.OsmosisModule{} qid := icqkeeper.GenerateQueryHash("connection-77002", "osmosis-1", "store/gamm/key", osm.GetKeyPrefixPools(1), types.ModuleName) query, found := prk.IcqKeeper.GetQuery(ctx, qid) - s.Require().True(found, "qid: %s", qid) + suite.Require().True(found, "qid: %s", qid) var err error resp := []byte{10, 26, 47, 111, 115, 109, 111, 115, 105, 115, 46, 103, 97, 109, 109, 46, 118, 49, 98, 101, 116, 97, 49, 46, 80, 111, 111, 108, 18, 202, 2, 10, 63, 111, 115, 109, 111, 49, 109, 119, 48, 97, 99, 54, 114, 119, 108, 112, 53, 114, 56, 119, 97, 112, 119, 107, 51, 122, 115, 54, 103, 50, 57, 104, 56, 102, 99, 115, 99, 120, 113, 97, 107, 100, 122, 119, 57, 101, 109, 107, 110, 101, 54, 99, 56, 119, 106, 112, 57, 113, 48, 116, 51, 118, 56, 116, 16, 1, 26, 6, 10, 1, 48, 18, 1, 48, 34, 4, 49, 54, 56, 104, 42, 43, 10, 11, 103, 97, 109, 109, 47, 112, 111, 111, 108, 47, 49, 18, 28, 49, 48, 48, 48, 48, 48, 48, 50, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 48, 48, 50, 94, 10, 80, 10, 68, 105, 98, 99, 47, 49, 53, 69, 57, 67, 53, 67, 70, 53, 57, 54, 57, 48, 56, 48, 53, 51, 57, 68, 66, 51, 57, 53, 70, 65, 55, 68, 57, 67, 48, 56, 54, 56, 50, 54, 53, 50, 49, 55, 69, 70, 67, 53, 50, 56, 52, 51, 51, 54, 55, 49, 65, 65, 70, 57, 66, 49, 57, 49, 50, 68, 49, 53, 57, 18, 8, 49, 48, 48, 48, 48, 48, 48, 51, 18, 10, 49, 48, 55, 51, 55, 52, 49, 56, 50, 52, 50, 94, 10, 80, 10, 68, 105, 98, 99, 47, 51, 48, 50, 48, 57, 50, 50, 66, 55, 53, 55, 54, 70, 67, 55, 53, 66, 66, 69, 48, 53, 55, 65, 48, 50, 57, 48, 65, 57, 65, 69, 69, 70, 70, 52, 56, 57, 66, 66, 49, 49, 49, 51, 69, 54, 69, 51, 54, 53, 67, 69, 52, 55, 50, 68, 52, 66, 70, 66, 55, 70, 70, 65, 51, 18, 8, 49, 48, 48, 48, 48, 48, 48, 51, 18, 10, 49, 48, 55, 51, 55, 52, 49, 56, 50, 52, 58, 10, 50, 49, 52, 55, 52, 56, 51, 54, 52, 56} @@ -34,9 +34,9 @@ func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { // setup for expected var pdi gamm.PoolI err = prk.GetCodec().UnmarshalInterface(resp, &pdi) - s.Require().NoError(err) + suite.Require().NoError(err) expectedData, err := json.Marshal(pdi) - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.OsmosisPoolUpdateCallback( ctx, @@ -44,7 +44,7 @@ func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { resp, query, ) - s.Require().NoError(err) + suite.Require().NoError(err) want := &types.OsmosisPoolProtocolData{ PoolID: 1, @@ -52,38 +52,38 @@ func (s *KeeperTestSuite) executeOsmosisPoolUpdateCallback() { LastUpdated: ctx.BlockTime(), PoolData: expectedData, PoolType: "balancer", - Zones: map[string]string{ - "cosmoshub-4": "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", - "osmosis-1": "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159", + Denoms: map[string]types.DenomWithZone{ + "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3": {ChainID: "cosmoshub-4", Denom: "uatom"}, + "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159": {ChainID: "osmosis-1", Denom: "uosmo"}, }, } pd, found := prk.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisPool, "1") - s.Require().True(found) + suite.Require().True(found) ioppd, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisPool, pd.Data) - s.Require().NoError(err) + suite.Require().NoError(err) oppd := ioppd.(*types.OsmosisPoolProtocolData) - s.Require().Equal(want, oppd) + suite.Require().Equal(want, oppd) } -func (s *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAddress string, valRewards map[string]sdk.Dec) { - prk := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAddress string, valRewards map[string]sdk.Dec) { + prk := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper + ctx := suite.chainA.GetContext() rewardsQuery := distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: performanceAddress} bz := prk.GetCodec().MustMarshal(&rewardsQuery) qid := icqkeeper.GenerateQueryHash( - s.path.EndpointA.ConnectionID, - s.chainB.ChainID, + suite.path.EndpointA.ConnectionID, + suite.chainB.ChainID, "cosmos.distribution.v1beta1.Query/DelegationTotalRewards", bz, types.ModuleName, ) query, found := prk.IcqKeeper.GetQuery(ctx, qid) - s.Require().True(found, "qid: %s", qid) + suite.Require().True(found, "qid: %s", qid) var respJSON strings.Builder respJSON.Write([]byte(`{"rewards":[`)) @@ -100,9 +100,9 @@ func (s *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAd respJSON.Write([]byte(fmt.Sprintf(`],"total":[{"denom":"uatom","amount":%q}]}`, total.String()))) qdtrResp := distrtypes.QueryDelegationTotalRewardsResponse{} err := json.Unmarshal([]byte(respJSON.String()), &qdtrResp) - s.Require().NoError(err) + suite.Require().NoError(err) resp, err := qdtrResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.ValidatorSelectionRewardsCallback( ctx, @@ -110,32 +110,32 @@ func (s *KeeperTestSuite) executeValidatorSelectionRewardsCallback(performanceAd resp, query, ) - s.Require().NoError(err) + suite.Require().NoError(err) } -func (s *KeeperTestSuite) executeSetEpochBlockCallback() { - prk := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper - ctx := s.chainA.GetContext() +func (suite *KeeperTestSuite) executeSetEpochBlockCallback() { + prk := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper + ctx := suite.chainA.GetContext() blockQuery := tmservice.GetLatestBlockRequest{} bz := prk.GetCodec().MustMarshal(&blockQuery) qid := icqkeeper.GenerateQueryHash( - s.path.EndpointA.ConnectionID, - s.chainB.ChainID, + suite.path.EndpointA.ConnectionID, + suite.chainB.ChainID, "cosmos.base.tendermint.v1beta1.Service/GetLatestBlock", bz, types.ModuleName, ) query, found := prk.IcqKeeper.GetQuery(ctx, qid) - s.Require().True(found, "qid: %s", qid) + suite.Require().True(found, "qid: %s", qid) respJSON := `{"block_id":{"hash":"74pkkjg7u1eLtXxFCinnCmln3aVZVOqLCT3OnE3D+VA=","part_set_header":{"total":1,"hash":"UiLM70PpplmmZ85qC0ZKva5kYJmSZ2TTEZ4a7g9G92Q="}},"block":{"header":{"version":{"block":"11","app":"0"},"chain_id":"quickgaia-1","height":"90767","time":"2022-11-03T09:12:23.109926769Z","last_block_id":{"hash":"wCK5QmPuGJiRpn06Xu7ZjhxHwzBXVZrGqngMMzeRq8w=","part_set_header":{"total":1,"hash":"xYxXM7rX6Qcq/Yx3MpZeQA+FCeUbKSVr/FEuzfAFFQk="}},"last_commit_hash":"1Ev2iL1pTgyItBtSFbCRzxwdCtJfaCC1P+zWaDkJ/nU=","data_hash":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=","validators_hash":"kQ9NNQ26Q3l5aXF2IwraaweoLzusIVDUA53AycOe1PI=","next_validators_hash":"kQ9NNQ26Q3l5aXF2IwraaweoLzusIVDUA53AycOe1PI=","consensus_hash":"BICRvH3cKD93v7+R1zxE2ljD34qcvIZ0Bdi389qtoi8=","app_hash":"j3x5PuEH14QVBqWUv6BhKitzXMTJ2w47h2Nj99JKtlI=","last_results_hash":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=","evidence_hash":"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=","proposer_address":"YVEp2+U79qlwIpwaKr4rObvWbHo="},"data":{"txs":[]},"evidence":{"evidence":[]},"last_commit":{"height":"90766","round":0,"block_id":{"hash":"wCK5QmPuGJiRpn06Xu7ZjhxHwzBXVZrGqngMMzeRq8w=","part_set_header":{"total":1,"hash":"xYxXM7rX6Qcq/Yx3MpZeQA+FCeUbKSVr/FEuzfAFFQk="}},"signatures":[{"block_id_flag":"BLOCK_ID_FLAG_COMMIT","validator_address":"WRBCW5t/kdjOaTvYz9TaySfc8xU=","timestamp":"2022-11-03T09:12:23.109926769Z","signature":"LAbAFCM2MlT1QeNnhZoD8xPe6fO6GExtDNdwa8sokr9UZjurHWn3ad9U2BhTLFVKUF6j7r9G9ILKshljKn4/Aw=="},{"block_id_flag":"BLOCK_ID_FLAG_COMMIT","validator_address":"YVEp2+U79qlwIpwaKr4rObvWbHo=","timestamp":"2022-11-03T09:12:23.104507119Z","signature":"KxHLYnn97GG9prtLA+qurq5GvZogcoExpCvWmOOd8uS3m1Tug5qptSxZ2AObiUfyDwl23oqNNEhkp2XxsxcOCA=="},{"block_id_flag":"BLOCK_ID_FLAG_COMMIT","validator_address":"agVlYuY3F6RGyBUe5zgd0oFhoCM=","timestamp":"2022-11-03T09:12:23.109928409Z","signature":"vvL6yIdxyT4Eus/xw8/RWvFymUFNiOsJ+hHM/qwSJQt427hdUiIh/iH6+yZGz5bdpChW4/Y4bB1QnIA8q1SjBw=="}]}}}` glbrResp := tmservice.GetLatestBlockResponse{} - err := s.GetQuicksilverApp(s.chainA).AppCodec().UnmarshalJSON([]byte(respJSON), &glbrResp) - s.Require().NoError(err) + err := suite.GetQuicksilverApp(suite.chainA).AppCodec().UnmarshalJSON([]byte(respJSON), &glbrResp) + suite.Require().NoError(err) resp, err := glbrResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) err = keeper.SetEpochBlockCallback( ctx, @@ -143,5 +143,5 @@ func (s *KeeperTestSuite) executeSetEpochBlockCallback() { resp, query, ) - s.Require().NoError(err) + suite.Require().NoError(err) } diff --git a/x/participationrewards/keeper/distribution.go b/x/participationrewards/keeper/distribution.go index 4d335437e..bcd40120b 100644 --- a/x/participationrewards/keeper/distribution.go +++ b/x/participationrewards/keeper/distribution.go @@ -8,37 +8,36 @@ import ( "github.com/ingenuity-build/quicksilver/internal/multierror" "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" icstypes "github.com/ingenuity-build/quicksilver/x/interchainstaking/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -type tokenValues map[string]sdk.Dec +type TokenValues map[string]sdk.Dec -func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { +func (k *Keeper) CalcTokenValues(ctx sdk.Context) (TokenValues, error) { k.Logger(ctx).Info("calcTokenValues") - tvs := make(map[string]sdk.Dec) - - // get base zone (Cosmos) - var cosmosZone *icstypes.Zone - k.icsKeeper.IterateZones(ctx, func(_ int64, zone *icstypes.Zone) (stop bool) { - if zone.AccountPrefix == "cosmos" { - cosmosZone = zone - return true - } - return false - }) - if cosmosZone == nil { - return nil, errors.New("unable to find Cosmos zone") + data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeOsmosisParams, "osmosisparams") + if !found { + return TokenValues{}, errors.New("could not find osmosisparams protocol data") + } + osmoParams, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisParams, data.Data) + if err != nil { + return TokenValues{}, err } + baseDenom := osmoParams.(*types.OsmosisParamsProtocolData).BaseDenom + baseChain := osmoParams.(*types.OsmosisParamsProtocolData).BaseChain + + tvs := make(map[string]sdk.Dec) + // add base value - tvs[cosmosZone.BaseDenom] = sdk.OneDec() - // tvs[uatom] = 1.0 + tvs[baseDenom] = sdk.OneDec() - // capture errors from iterator + // capture errors from iteratora errs := make(map[string]error) - k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, data types.ProtocolData) bool { + k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, _ []byte, data types.ProtocolData) bool { idxLabel := fmt.Sprintf("index[%d]", idx) ipool, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisPool, data.Data) if err != nil { @@ -47,8 +46,8 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { } pool, _ := ipool.(*types.OsmosisPoolProtocolData) - // pool must be a cosmos pair - if len(pool.Zones) != 2 { + // pool must be a base pair + if len(pool.Denoms) != 2 { // not a pair: skip return false } @@ -58,36 +57,40 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { // - queryIBCDenom -> the target IBC denom in this pair // - valueDenom -> the target zone.BaseDenom var baseIBCDenom, queryIBCDenom, valueDenom string - isCosmosPair := false - - for chainID, denom := range pool.Zones { - zone, ok := k.icsKeeper.GetZone(ctx, chainID) - if !ok { - errs[idxLabel] = fmt.Errorf("zone not found, %s", chainID) - return true - } - - if zone.AccountPrefix == "cosmos" { - isCosmosPair = true - baseIBCDenom = denom - continue + isBasePair := false + + for _, ibcDenom := range utils.Keys(pool.Denoms) { + if pool.Denoms[ibcDenom].ChainID == baseChain { + isBasePair = true + baseIBCDenom = ibcDenom + } else { + zone, ok := k.icsKeeper.GetZone(ctx, pool.Denoms[ibcDenom].ChainID) + if !ok { + // errs[idxLabel] = fmt.Errorf("zone not found, %s", denom.ChainId) + return false + } + + if pool.Denoms[ibcDenom].Denom == zone.BaseDenom { + queryIBCDenom = ibcDenom + valueDenom = zone.BaseDenom + } else { + return false + } } - - queryIBCDenom = denom - valueDenom = zone.BaseDenom } - if isCosmosPair { + if isBasePair { if pool.PoolData == nil { errs[idxLabel] = fmt.Errorf("pool data is nil, awaiting OsmosisPoolUpdateCallback") return true } - pool, err := pool.GetPool() + gammPool, err := pool.GetPool() if err != nil { errs[idxLabel] = err return true } - value, err := pool.SpotPrice(ctx, baseIBCDenom, queryIBCDenom) + + value, err := gammPool.SpotPrice(ctx, baseIBCDenom, queryIBCDenom) if err != nil { errs[idxLabel] = err return true @@ -109,10 +112,10 @@ func (k *Keeper) calcTokenValues(ctx sdk.Context) (tokenValues, error) { // AllocateZoneRewards executes zone based rewards allocation. This entails // rewards that are proportionally distributed to zones based on the tvl for // each zone relative to the tvl of the QS protocol. -func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { +func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs TokenValues, allocation types.RewardsAllocation) error { k.Logger(ctx).Info("allocateZoneRewards", "token values", tvs, "allocation", allocation) - if err := k.setZoneAllocations(ctx, tvs, allocation); err != nil { + if err := k.SetZoneAllocations(ctx, tvs, allocation); err != nil { return err } @@ -121,31 +124,28 @@ func (k *Keeper) AllocateZoneRewards(ctx sdk.Context, tvs tokenValues, allocatio return k.AllocateHoldingsRewards(ctx) } -// setZoneAllocations returns the proportional zone rewards allocations as a +// SetZoneAllocations returns the proportional zone rewards allocations as a // map indexed by the zone id. -func (k *Keeper) setZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation types.RewardsAllocation) error { +func (k *Keeper) SetZoneAllocations(ctx sdk.Context, tvs TokenValues, allocation types.RewardsAllocation) error { k.Logger(ctx).Info("setZoneAllocations", "allocation", allocation) otvl := sdk.ZeroDec() // pass 1: iterate zones - set tvl & calc overall tvl - for _, zone := range k.icsKeeper.AllZones(ctx) { - // explicit memory referencing - zone := zone - + k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { tv, exists := tvs[zone.BaseDenom] if !exists { k.Logger(ctx).Error(fmt.Sprintf("unable to obtain token value for zone %s", zone.ChainId)) - continue + return false } - ztvl := sdk.NewDecFromInt(k.icsKeeper.GetDelegatedAmount(ctx, &zone).Amount.Add(k.icsKeeper.GetDelegationsInProcess(ctx, &zone))).Mul(tv) - + ztvl := sdk.NewDecFromInt(k.icsKeeper.GetDelegatedAmount(ctx, zone).Amount.Add(k.icsKeeper.GetDelegationsInProcess(ctx, zone))).Mul(tv) zone.Tvl = ztvl - k.icsKeeper.SetZone(ctx, &zone) + k.icsKeeper.SetZone(ctx, zone) k.Logger(ctx).Info("zone tvl", "zone", zone.ChainId, "tvl", ztvl) otvl = otvl.Add(ztvl) - } + return false + }) // check overall protocol tvl if otvl.IsZero() { @@ -154,10 +154,7 @@ func (k *Keeper) setZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation } // pass 2: iterate zones - calc zone tvl proportion & set allocations - for _, zone := range k.icsKeeper.AllZones(ctx) { - // explicit memory referencing - zone := zone - + k.icsKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { if zone.Tvl.IsNil() { zone.Tvl = sdk.ZeroDec() } @@ -167,9 +164,9 @@ func (k *Keeper) setZoneAllocations(ctx sdk.Context, tvs tokenValues, allocation zone.ValidatorSelectionAllocation = sdk.NewDecFromInt(allocation.ValidatorSelection).Mul(zp).TruncateInt().Uint64() zone.HoldingsAllocation = sdk.NewDecFromInt(allocation.Holdings).Mul(zp).TruncateInt().Uint64() - - k.icsKeeper.SetZone(ctx, &zone) - } + k.icsKeeper.SetZone(ctx, zone) + return false + }) return nil } @@ -191,7 +188,7 @@ func (k *Keeper) DistributeToUsers(ctx sdk.Context, userAllocations []types.User ), ) - addrBytes, err := utils.AccAddressFromBech32(ua.Address, "") + addrBytes, err := addressutils.AccAddressFromBech32(ua.Address, "") if err != nil { k.Logger(ctx).Error("unmarshalling address", "address", ua.Address) hasError = true diff --git a/x/participationrewards/keeper/distribution_test.go b/x/participationrewards/keeper/distribution_test.go index 942926490..c0af82860 100644 --- a/x/participationrewards/keeper/distribution_test.go +++ b/x/participationrewards/keeper/distribution_test.go @@ -1 +1,109 @@ package keeper_test + +import ( + "encoding/json" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" + "github.com/ingenuity-build/quicksilver/x/participationrewards/types" +) + +func (suite *KeeperTestSuite) TestCalcTokenValues() { + type cases struct { + name string + osmosisParams types.OsmosisParamsProtocolData + osmosisPools []types.OsmosisPoolProtocolData + expectedTvs keeper.TokenValues + } + + tests := []cases{ + { + osmosisParams: types.OsmosisParamsProtocolData{ + ChainID: "osmosis-1", + BaseDenom: "uosmo", + BaseChain: "osmosis-1", + }, + osmosisPools: []types.OsmosisPoolProtocolData{ + { + PoolID: 956, + PoolName: "qOsmo/osmo", + LastUpdated: time.Now().UTC(), + PoolType: "stableswap", + PoolData: json.RawMessage("{\"address\":\"osmo1q023e9m4d3ffvr96xwaeraa62yfvufkufkr7yf7lmacgkuspsuqsga4xp2\",\"id\":956,\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\"},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/956\",\"amount\":\"118922578939571354422559\"},\"pool_liquidity\":[{\"denom\":\"ibc/42D24879D4569CE6477B7E88206ADBFE47C222C6CAD51A54083E4A72594269FC\",\"amount\":\"217240952822\"},{\"denom\":\"uosmo\",\"amount\":\"260096955062\"}],\"scaling_factors\":[\"1000000000\",\"1045466083\"],\"scaling_factor_controller\":\"osmo16x03wcp37kx5e8ehckjxvwcgk9j0cqnhm8m3yy\"}"), + Denoms: map[string]types.DenomWithZone{}, + IsIncentivized: true, + }, + { + PoolID: 944, + PoolName: "atom/qAtom", + LastUpdated: time.Now().UTC(), + PoolType: "stableswap", + PoolData: json.RawMessage("{\"address\":\"osmo1awr39mc2hrkt8gq8gt3882ru40ay45k8a3yg69nyypqe9g0ryycs66lhkh\",\"id\":944,\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\"},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/944\",\"amount\":\"9298235648962291280150\"},\"pool_liquidity\":[{\"denom\":\"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\",\"amount\":\"73166403902\"},{\"denom\":\"ibc/FA602364BEC305A696CBDF987058E99D8B479F0318E47314C49173E8838C5BAC\",\"amount\":\"98593533184\"}],\"scaling_factors\":[\"1071353717\",\"1000000000\"],\"scaling_factor_controller\":\"osmo16x03wcp37kx5e8ehckjxvwcgk9j0cqnhm8m3yy\"}"), + Denoms: map[string]types.DenomWithZone{}, + IsIncentivized: true, + }, + { + PoolID: 1, + PoolName: "Atom/Osmo", + LastUpdated: time.Now().UTC(), + PoolType: "balancer", + PoolData: json.RawMessage("{\"address\":\"osmo1mw0ac6rwlp5r8wapwk3zs6g29h8fcscxqakdzw9emkne6c8wjp9q0t3v8t\",\"id\":1,\"pool_params\":{\"swap_fee\":\"0.002000000000000000\",\"exit_fee\":\"0.000000000000000000\",\"smooth_weight_change_params\":null},\"future_pool_governor\":\"24h\",\"total_shares\":{\"denom\":\"gamm/pool/1\",\"amount\":\"216987393856026889179749817\"},\"pool_assets\":[{\"token\":{\"denom\":\"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\",\"amount\":\"1909639500022\"},\"weight\":\"536870912000000\"},{\"token\":{\"denom\":\"uosmo\",\"amount\":\"35673230362499\"},\"weight\":\"536870912000000\"}],\"total_weight\":\"1073741824000000\"}"), + Denoms: map[string]types.DenomWithZone{ + "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainID: "cosmoshub-4"}, + "uosmo": {Denom: "uosmo", ChainID: "osmosis-1"}, + }, + IsIncentivized: false, + }, + { + PoolID: 952, + PoolName: "qck/osmo", + LastUpdated: time.Now().UTC(), + PoolType: "balancer", + PoolData: json.RawMessage("{\"address\":\"osmo1k3j5wgcj8um2gnu8qxdm0mzzuh6x66p4p7gn6fraf3wnpfcvg9sq2zhx7j\",\"id\":\"952\",\"pool_params\":{\"swap_fee\":\"0.003000000000000000\",\"exit_fee\":\"0.000000000000000000\",\"smooth_weight_change_params\":null},\"future_pool_governor\":\"168h\",\"total_shares\":{\"denom\":\"gamm/pool/952\",\"amount\":\"281109110456689694028077\"},\"pool_assets\":[{\"token\":{\"denom\":\"ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D\",\"amount\":\"1036526700301\"},\"weight\":\"1073741824\"},{\"token\":{\"denom\":\"uosmo\",\"amount\":\"162265452817\"},\"weight\":\"1073741824\"}],\"total_weight\":\"2147483648\"}"), + Denoms: map[string]types.DenomWithZone{ + "ibc/635CB83EF1DFE598B10A3E90485306FD0D47D34217A4BE5FD9977FA010A5367D": {Denom: "uqck", ChainID: "quicksilver-2"}, + "uosmo": {Denom: "uosmo", ChainID: "osmosis-1"}, + }, + IsIncentivized: false, + }, + }, + expectedTvs: keeper.TokenValues{ + "uatom": sdk.MustNewDecFromStr("18.680609802053228677"), + "uosmo": sdk.MustNewDecFromStr("1.000000000000000000"), + }, + }, + } + + for _, tt := range tests { + tt := tt + + suite.Run(tt.name, func() { + suite.SetupTest() + + qs := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + osmoParamsJSON, err := json.Marshal(tt.osmosisParams) + suite.Require().NoError(err) + data := types.ProtocolData{ + Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisParams)], + Data: osmoParamsJSON, + } + qs.ParticipationRewardsKeeper.SetProtocolData(ctx, tt.osmosisParams.GenerateKey(), &data) + + for _, pool := range tt.osmosisPools { + poolJSON, err := json.Marshal(pool) + suite.Require().NoError(err) + data := types.ProtocolData{ + Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeOsmosisPool)], + Data: poolJSON, + } + qs.ParticipationRewardsKeeper.SetProtocolData(ctx, pool.GenerateKey(), &data) + } + tvs, err := qs.ParticipationRewardsKeeper.CalcTokenValues(ctx) + suite.Require().NoError(err) + suite.Require().Equal(tt.expectedTvs, tvs) + }) + } +} diff --git a/x/participationrewards/keeper/grpc_query.go b/x/participationrewards/keeper/grpc_query.go index 42c7db418..b4fb86348 100644 --- a/x/participationrewards/keeper/grpc_query.go +++ b/x/participationrewards/keeper/grpc_query.go @@ -29,7 +29,7 @@ func (k *Keeper) ProtocolData(c context.Context, q *types.QueryProtocolDataReque } prefix := append(types.GetPrefixProtocolDataKey(types.ProtocolDataType(pdType)), []byte(q.Key)...) - k.IteratePrefixedProtocolDatas(ctx, prefix, func(index int64, data types.ProtocolData) (stop bool) { + k.IteratePrefixedProtocolDatas(ctx, prefix, func(index int64, _ []byte, data types.ProtocolData) (stop bool) { out = append(out, data.Data) return false }) diff --git a/x/participationrewards/keeper/grpc_query_test.go b/x/participationrewards/keeper/grpc_query_test.go index f2312b7a4..a0a81a8f6 100644 --- a/x/participationrewards/keeper/grpc_query_test.go +++ b/x/participationrewards/keeper/grpc_query_test.go @@ -7,37 +7,37 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) TestKeeper_Params() { - s.Run("Params", func() { - k := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper +func (suite *KeeperTestSuite) TestKeeper_Params() { + suite.Run("Params", func() { + k := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper want := types.QueryParamsResponse{ Params: types.DefaultParams(), } - got, err := k.Params(s.chainA.GetContext(), &types.QueryParamsRequest{}) - s.Require().NoError(err) - s.Require().NotNil(got) - s.Require().Equal(want, *got) + got, err := k.Params(suite.chainA.GetContext(), &types.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().NotNil(got) + suite.Require().Equal(want, *got) }) } -func (s *KeeperTestSuite) TestKeeper_ProtocolData() { - connpdstr := fmt.Sprintf("{\"ConnectionID\":%q,\"ChainID\":%q,\"LastEpoch\":%d,\"Prefix\":\"\"}", s.path.EndpointB.ConnectionID, s.chainB.ChainID, 90767) - s.Run("ProtocolData", func() { - k := s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper +func (suite *KeeperTestSuite) TestKeeper_ProtocolData() { + connpdstr := fmt.Sprintf("{\"ConnectionID\":%q,\"ChainID\":%q,\"LastEpoch\":%d,\"Prefix\":\"\"}", suite.path.EndpointB.ConnectionID, suite.chainB.ChainID, 90767) + suite.Run("ProtocolData", func() { + k := suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper want := types.QueryProtocolDataResponse{ Data: []encoding_json.RawMessage{ []byte(connpdstr), }, } got, err := k.ProtocolData( - s.chainA.GetContext(), + suite.chainA.GetContext(), &types.QueryProtocolDataRequest{ Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeConnection)], - Key: s.chainB.ChainID, + Key: suite.chainB.ChainID, }, ) - s.Require().NoError(err) - s.Require().NotNil(got) - s.Require().Equal(want, *got) + suite.Require().NoError(err) + suite.Require().NotNil(got) + suite.Require().Equal(want, *got) }) } diff --git a/x/participationrewards/keeper/hooks.go b/x/participationrewards/keeper/hooks.go index 807fa3307..300c21755 100644 --- a/x/participationrewards/keeper/hooks.go +++ b/x/participationrewards/keeper/hooks.go @@ -14,7 +14,7 @@ func (k *Keeper) BeforeEpochStart(_ sdk.Context, _ string, _ int64) error { func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64) error { if epochIdentifier == epochstypes.EpochIdentifierEpoch { - k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeConnection), func(index int64, data types.ProtocolData) (stop bool) { + k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeConnection), func(index int64, _ []byte, data types.ProtocolData) (stop bool) { blockQuery := tmservice.GetLatestBlockRequest{} bz := k.cdc.MustMarshal(&blockQuery) @@ -62,7 +62,7 @@ func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ int64) sub.Hooks(ctx, k) } - tvs, err := k.calcTokenValues(ctx) + tvs, err := k.CalcTokenValues(ctx) if err != nil { k.Logger(ctx).Error("unable to calculate token values", "error", err.Error()) return nil diff --git a/x/participationrewards/keeper/keeper.go b/x/participationrewards/keeper/keeper.go index 301770599..9d0ed4293 100644 --- a/x/participationrewards/keeper/keeper.go +++ b/x/participationrewards/keeper/keeper.go @@ -118,12 +118,13 @@ func (k *Keeper) GetCodec() codec.BinaryCodec { } func (k *Keeper) UpdateSelfConnectionData(ctx sdk.Context) error { - selfConnectionData, err := json.Marshal(types.ConnectionProtocolData{ + selfConnectionData := types.ConnectionProtocolData{ ConnectionID: types.SelfConnection, ChainID: ctx.ChainID(), LastEpoch: ctx.BlockHeight() - 2, // reason why -2 works here. Prefix: config.Bech32Prefix, - }) + } + selfConnectionDataBlob, err := json.Marshal(selfConnectionData) if err != nil { k.Logger(ctx).Info("Error Marshalling self connection Data") return err @@ -131,10 +132,10 @@ func (k *Keeper) UpdateSelfConnectionData(ctx sdk.Context) error { data := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeConnection)], - Data: selfConnectionData, + Data: selfConnectionDataBlob, } k.Logger(ctx).Info("Setting self protocol data", "data", data) - k.SetProtocolData(ctx, ctx.ChainID(), &data) + k.SetProtocolData(ctx, selfConnectionData.GenerateKey(), &data) return nil } diff --git a/x/participationrewards/keeper/keeper_test.go b/x/participationrewards/keeper/keeper_test.go index 1b4dc953d..e89436e97 100644 --- a/x/participationrewards/keeper/keeper_test.go +++ b/x/participationrewards/keeper/keeper_test.go @@ -5,12 +5,11 @@ import ( "testing" "time" - "github.com/stretchr/testify/suite" + testsuite "github.com/stretchr/testify/suite" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -19,7 +18,7 @@ import ( ibctesting "github.com/cosmos/ibc-go/v5/testing" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" epochtypes "github.com/ingenuity-build/quicksilver/x/epochs/types" ics "github.com/ingenuity-build/quicksilver/x/interchainstaking" @@ -27,7 +26,7 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -var testAddress = utils.GenerateAccAddressForTest().String() +var testAddress = addressutils.GenerateAddressForTestWithPrefix("cosmos") func init() { ibctesting.DefaultTestingAppInit = app.SetupTestingApp @@ -35,7 +34,7 @@ func init() { // TestKeeperTestSuite runs all the tests within this package. func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) + testsuite.Run(t, new(KeeperTestSuite)) } func newQuicksilverPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { @@ -47,7 +46,7 @@ func newQuicksilverPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path { } type KeeperTestSuite struct { - suite.Suite + testsuite.Suite coordinator *ibctesting.Coordinator @@ -58,7 +57,7 @@ type KeeperTestSuite struct { path *ibctesting.Path } -func (s *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quicksilver { +func (suite *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quicksilver { quicksilver, ok := chain.App.(*app.Quicksilver) if !ok { panic("not quicksilver app") @@ -68,85 +67,85 @@ func (s *KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Qu } // SetupTest creates a coordinator with 2 test chains. -func (s *KeeperTestSuite) SetupTest() { - s.coordinator = ibctesting.NewCoordinator(s.T(), 2) // initializes 2 test chains - s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability - s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability +func (suite *KeeperTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initializes 2 test chains + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability + suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability - s.path = newQuicksilverPath(s.chainA, s.chainB) - s.coordinator.SetupConnections(s.path) + suite.path = newQuicksilverPath(suite.chainA, suite.chainB) + suite.coordinator.SetupConnections(suite.path) - s.coordinator.CurrentTime = time.Now().UTC() - s.coordinator.UpdateTime() + suite.coordinator.CurrentTime = time.Now().UTC() + suite.coordinator.UpdateTime() - s.coreTest() + suite.coreTest() } -func (s *KeeperTestSuite) coreTest() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) coreTest() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) - s.setupTestZones() + suite.setupTestZones() // test ProtocolData - akpd := quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(s.chainA.GetContext()) + akpd := quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(suite.chainA.GetContext()) // initially we expect one - the 'local' chain - s.Require().Equal(1, len(akpd)) + suite.Require().Equal(1, len(akpd)) - s.setupTestProtocolData() + suite.setupTestProtocolData() - akpd = quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(s.chainA.GetContext()) + akpd = quicksilver.ParticipationRewardsKeeper.AllKeyedProtocolDatas(suite.chainA.GetContext()) // added 6 in setupTestProtocolData - s.Require().Equal(7, len(akpd)) + suite.Require().Equal(7, len(akpd)) // advance the chains - s.coordinator.CommitNBlocks(s.chainA, 1) - s.coordinator.CommitNBlocks(s.chainB, 1) + suite.coordinator.CommitNBlocks(suite.chainA, 1) + suite.coordinator.CommitNBlocks(suite.chainB, 1) // callback test - s.executeSetEpochBlockCallback() - s.executeOsmosisPoolUpdateCallback() + suite.executeSetEpochBlockCallback() + suite.executeOsmosisPoolUpdateCallback() - s.setupTestDeposits() - s.setupTestIntents() + suite.setupTestDeposits() + suite.setupTestIntents() - quicksilver.EpochsKeeper.AfterEpochEnd(s.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 1) + quicksilver.EpochsKeeper.AfterEpochEnd(suite.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 1) - s.setupTestClaims() + suite.setupTestClaims() - quicksilver.EpochsKeeper.AfterEpochEnd(s.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 2) + quicksilver.EpochsKeeper.AfterEpochEnd(suite.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 2) // Epoch boundary - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() quicksilver.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone *icstypes.Zone) (stop bool) { - s.Require().NoError(quicksilver.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) - s.Require().NoError(quicksilver.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(quicksilver.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(quicksilver.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(quicksilver.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) return false }) _, found := quicksilver.ClaimsManagerKeeper.GetLastEpochClaim(ctx, "cosmoshub-4", "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure", cmtypes.ClaimTypeLiquidToken, "osmosis-1") - s.Require().True(found) + suite.Require().True(found) - quicksilver.EpochsKeeper.AfterEpochEnd(s.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 3) + quicksilver.EpochsKeeper.AfterEpochEnd(suite.chainA.GetContext(), epochtypes.EpochIdentifierEpoch, 3) // zone for remote chain - zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) valRewards := make(map[string]sdk.Dec) - for _, val := range quicksilver.InterchainstakingKeeper.GetValidators(s.chainA.GetContext(), s.chainB.ChainID) { + for _, val := range quicksilver.InterchainstakingKeeper.GetValidators(suite.chainA.GetContext(), suite.chainB.ChainID) { valRewards[val.ValoperAddress] = sdk.NewDec(100000000) } - s.executeValidatorSelectionRewardsCallback(zone.PerformanceAddress.Address, valRewards) + suite.executeValidatorSelectionRewardsCallback(zone.PerformanceAddress.Address, valRewards) } -func (s *KeeperTestSuite) setupTestZones() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupTestZones() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) // test zone testzone := icstypes.Zone{ - ConnectionId: s.path.EndpointA.ConnectionID, - ChainId: s.chainB.ChainID, + ConnectionId: suite.path.EndpointA.ConnectionID, + ChainId: suite.chainB.ChainID, AccountPrefix: "cosmos", LocalDenom: "uqatom", BaseDenom: "uatom", @@ -157,8 +156,8 @@ func (s *KeeperTestSuite) setupTestZones() { Is_118: true, } selftestzone := icstypes.Zone{ - ConnectionId: s.path.EndpointB.ConnectionID, - ChainId: s.chainA.ChainID, + ConnectionId: suite.path.EndpointB.ConnectionID, + ChainId: suite.chainA.ChainID, AccountPrefix: "osmo", LocalDenom: "uqosmo", BaseDenom: "uosmo", @@ -169,27 +168,27 @@ func (s *KeeperTestSuite) setupTestZones() { Is_118: true, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &selftestzone) - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &testzone) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &selftestzone) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &testzone) - quicksilver.IBCKeeper.ClientKeeper.SetClientState(s.chainA.GetContext(), "07-tendermint-0", &tmclienttypes.ClientState{ChainId: s.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}}) + quicksilver.IBCKeeper.ClientKeeper.SetClientState(suite.chainA.GetContext(), "07-tendermint-0", &tmclienttypes.ClientState{ChainId: suite.chainB.ChainID, TrustingPeriod: time.Hour, LatestHeight: clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}}) - quicksilver.IBCKeeper.ClientKeeper.SetClientConsensusState(s.chainA.GetContext(), "07-tendermint-0", clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}, &tmclienttypes.ConsensusState{Timestamp: s.chainA.GetContext().BlockTime()}) - s.Require().NoError(s.setupChannelForICA(s.chainB.ChainID, s.path.EndpointA.ConnectionID, "performance", testzone.AccountPrefix)) + quicksilver.IBCKeeper.ClientKeeper.SetClientConsensusState(suite.chainA.GetContext(), "07-tendermint-0", clienttypes.Height{RevisionNumber: 1, RevisionHeight: 100}, &tmclienttypes.ConsensusState{Timestamp: suite.chainA.GetContext().BlockTime()}) + suite.Require().NoError(suite.setupChannelForICA(suite.chainB.ChainID, suite.path.EndpointA.ConnectionID, "performance", testzone.AccountPrefix)) - vals := s.GetQuicksilverApp(s.chainB).StakingKeeper.GetBondedValidatorsByPower(s.chainB.GetContext()) - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + vals := suite.GetQuicksilverApp(suite.chainB).StakingKeeper.GetBondedValidatorsByPower(suite.chainB.GetContext()) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) for i := range vals { - s.Require().NoError(quicksilver.InterchainstakingKeeper.SetValidatorForZone(s.chainA.GetContext(), &zone, app.DefaultConfig().Codec.MustMarshal(&vals[i]))) + suite.Require().NoError(quicksilver.InterchainstakingKeeper.SetValidatorForZone(suite.chainA.GetContext(), &zone, app.DefaultConfig().Codec.MustMarshal(&vals[i]))) } // self zone - performanceAddressOsmo := utils.GenerateAccAddressForTestWithPrefix("osmo") + performanceAddressOsmo := addressutils.GenerateAddressForTestWithPrefix("osmo") performanceAccountOsmo, err := icstypes.NewICAAccount(performanceAddressOsmo, "self") - s.Require().NoError(err) - performanceAccountOsmo.WithdrawalAddress = utils.GenerateAccAddressForTestWithPrefix("osmo") + suite.Require().NoError(err) + performanceAccountOsmo.WithdrawalAddress = addressutils.GenerateAddressForTestWithPrefix("osmo") zoneSelf := icstypes.Zone{ ConnectionId: "connection-77004", @@ -228,13 +227,13 @@ func (s *KeeperTestSuite) setupTestZones() { }, }, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zoneSelf) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneSelf) // cosmos zone - performanceAddressCosmos := utils.GenerateAccAddressForTestWithPrefix("cosmos") + performanceAddressCosmos := addressutils.GenerateAddressForTestWithPrefix("cosmos") performanceAccountCosmos, err := icstypes.NewICAAccount(performanceAddressCosmos, "cosmoshub-4.performance") - s.Require().NoError(err) - performanceAccountCosmos.WithdrawalAddress = utils.GenerateAccAddressForTestWithPrefix("cosmos") + suite.Require().NoError(err) + performanceAccountCosmos.WithdrawalAddress = addressutils.GenerateAddressForTestWithPrefix("cosmos") zoneCosmos := icstypes.Zone{ ConnectionId: "connection-77001", @@ -247,7 +246,7 @@ func (s *KeeperTestSuite) setupTestZones() { PerformanceAddress: performanceAccountCosmos, Is_118: true, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zoneCosmos) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneCosmos) cosmosVals := []icstypes.Validator{ { ValoperAddress: "cosmosvaloper1759teakrsvnx7rnur8ezc4qaq8669nhtgukm0x", @@ -272,7 +271,7 @@ func (s *KeeperTestSuite) setupTestZones() { }, } for _, cosmosVal := range cosmosVals { - quicksilver.InterchainstakingKeeper.SetValidator(s.chainA.GetContext(), zoneCosmos.ChainId, cosmosVal) + quicksilver.InterchainstakingKeeper.SetValidator(suite.chainA.GetContext(), zoneCosmos.ChainId, cosmosVal) } // osmosis zone @@ -285,18 +284,18 @@ func (s *KeeperTestSuite) setupTestZones() { ReturnToSender: false, LiquidityModule: true, PerformanceAddress: &icstypes.ICAAccount{ - Address: utils.GenerateAccAddressForTestWithPrefix("osmo"), + Address: addressutils.GenerateAddressForTestWithPrefix("osmo"), PortName: "cosmoshub-4.performance", - WithdrawalAddress: utils.GenerateAccAddressForTestWithPrefix("osmo"), + WithdrawalAddress: addressutils.GenerateAddressForTestWithPrefix("osmo"), }, Is_118: true, } - quicksilver.InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zoneOsmosis) + quicksilver.InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zoneOsmosis) } -func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffix, remotePrefix string) error { - s.T().Helper() - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffix, remotePrefix string) error { + suite.T().Helper() + quicksilver := suite.GetQuicksilverApp(suite.chainA) ibcModule := ics.NewIBCModule(quicksilver.InterchainstakingKeeper) portID, err := icatypes.NewControllerPortID(chainID + "." + accountSuffix) @@ -304,22 +303,22 @@ func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffi return err } - quicksilver.InterchainstakingKeeper.SetConnectionForPort(s.chainA.GetContext(), connectionID, portID) + quicksilver.InterchainstakingKeeper.SetConnectionForPort(suite.chainA.GetContext(), connectionID, portID) - channelID := quicksilver.IBCKeeper.ChannelKeeper.GenerateChannelIdentifier(s.chainA.GetContext()) - quicksilver.IBCKeeper.ChannelKeeper.SetChannel(s.chainA.GetContext(), portID, channelID, channeltypes.Channel{State: channeltypes.OPEN, Ordering: channeltypes.ORDERED, Counterparty: channeltypes.Counterparty{PortId: icatypes.PortID, ChannelId: channelID}, ConnectionHops: []string{connectionID}}) + channelID := quicksilver.IBCKeeper.ChannelKeeper.GenerateChannelIdentifier(suite.chainA.GetContext()) + quicksilver.IBCKeeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, channelID, channeltypes.Channel{State: channeltypes.OPEN, Ordering: channeltypes.ORDERED, Counterparty: channeltypes.Counterparty{PortId: icatypes.PortID, ChannelId: channelID}, ConnectionHops: []string{connectionID}}) - quicksilver.IBCKeeper.ChannelKeeper.SetNextSequenceSend(s.chainA.GetContext(), portID, channelID, 1) - quicksilver.ICAControllerKeeper.SetActiveChannelID(s.chainA.GetContext(), connectionID, portID, channelID) + quicksilver.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), portID, channelID, 1) + quicksilver.ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), connectionID, portID, channelID) key, err := quicksilver.InterchainstakingKeeper.ScopedKeeper().NewCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), host.ChannelCapabilityPath(portID, channelID), ) if err != nil { return err } err = quicksilver.GetScopedIBCKeeper().ClaimCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), key, host.ChannelCapabilityPath(portID, channelID), ) @@ -328,14 +327,14 @@ func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffi } key, err = quicksilver.InterchainstakingKeeper.ScopedKeeper().NewCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), host.PortPath(portID), ) if err != nil { return err } err = quicksilver.GetScopedIBCKeeper().ClaimCapability( - s.chainA.GetContext(), + suite.chainA.GetContext(), key, host.PortPath(portID), ) @@ -343,90 +342,90 @@ func (s *KeeperTestSuite) setupChannelForICA(chainID, connectionID, accountSuffi return err } - addr, err := bech32.ConvertAndEncode(remotePrefix, utils.GenerateAccAddressForTest()) - if err != nil { - return err - } - quicksilver.ICAControllerKeeper.SetInterchainAccountAddress(s.chainA.GetContext(), connectionID, portID, addr) - return ibcModule.OnChanOpenAck(s.chainA.GetContext(), portID, channelID, "", "") + addr := addressutils.GenerateAddressForTestWithPrefix(remotePrefix) + quicksilver.ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), connectionID, portID, addr) + return ibcModule.OnChanOpenAck(suite.chainA.GetContext(), portID, channelID, "", "") } -func (s *KeeperTestSuite) setupTestProtocolData() { +func (suite *KeeperTestSuite) setupTestProtocolData() { // connection type for ibc testsuite chainB - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeConnection, - fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", s.path.EndpointB.ConnectionID, s.chainB.ChainID, 0), - s.chainB.ChainID, + []byte(fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", suite.path.EndpointB.ConnectionID, suite.chainB.ChainID, 0)), ) // osmosis params - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeOsmosisParams, - fmt.Sprintf("{\"ChainID\": %q}", "osmosis-1"), - types.OsmosisParamsKey, + []byte(fmt.Sprintf("{\"ChainID\": %q, \"BaseDenom\": %q, \"BaseChain\": %q}", "osmosis-1", "uosmo", "osmosis-1")), ) // osmosis test chain - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeConnection, - fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", "connection-77002", "osmosis-1", 0), - "osmosis-1", + []byte(fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d}", "connection-77002", "osmosis-1", 0)), ) // osmosis test pool - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeOsmosisPool, - fmt.Sprintf( - "{\"poolid\":%d,\"poolname\":%q,\"pooltype\":\"balancer\",\"zones\":{%q:%q,%q:%q}}", + []byte(fmt.Sprintf( + "{\"poolid\":%d,\"poolname\":%q,\"pooltype\":\"balancer\",\"denoms\":{%q:{\"chainid\": %q, \"denom\":%q}, %q:{\"chainid\": %q, \"denom\":%q}}}", 1, "atom/osmo", - "cosmoshub-4", "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", - "osmosis-1", + "cosmoshub-4", + "uatom", "ibc/15E9C5CF5969080539DB395FA7D9C0868265217EFC528433671AAF9B1912D159", - ), - "1", + "osmosis-1", + "uosmo", + )), ) + // atom (cosmoshub) on osmosis - s.addProtocolData( + suite.addProtocolData( types.ProtocolDataTypeLiquidToken, - fmt.Sprintf( + []byte(fmt.Sprintf( "{\"chainid\":%q,\"registeredzonechainid\":%q,\"ibcdenom\":%q,\"qassetdenom\":%q}", "osmosis-1", "cosmoshub-4", "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "uqatom", - ), - "osmosis-1/ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", + )), ) // atom (cosmoshub) on local chain - s.addProtocolData(types.ProtocolDataTypeLiquidToken, - fmt.Sprintf( + suite.addProtocolData(types.ProtocolDataTypeLiquidToken, + []byte(fmt.Sprintf( "{\"chainid\":%q,\"registeredzonechainid\":%q,\"ibcdenom\":%q,\"qassetdenom\":%q}", "testchain1", "cosmoshub-4", "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "uqatom", - ), - "testchain1/ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3") + )), + ) } -func (s *KeeperTestSuite) addProtocolData(dataType types.ProtocolDataType, data, key string) { - s.T().Helper() +func (suite *KeeperTestSuite) addProtocolData(dataType types.ProtocolDataType, data []byte) { + suite.T().Helper() pd := types.ProtocolData{ Type: types.ProtocolDataType_name[int32(dataType)], - Data: []byte(data), + Data: data, + } + + upd, err := types.UnmarshalProtocolData(dataType, pd.Data) + if err != nil { + panic(err) } - s.GetQuicksilverApp(s.chainA).ParticipationRewardsKeeper.SetProtocolData(s.chainA.GetContext(), key, &pd) + suite.GetQuicksilverApp(suite.chainA).ParticipationRewardsKeeper.SetProtocolData(suite.chainA.GetContext(), upd.GenerateKey(), &pd) } -func (s *KeeperTestSuite) setupTestDeposits() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupTestDeposits() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) // add deposit to chainB zone - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) - s.addReceipt( + suite.addReceipt( &zone, testAddress, "testTxHash03", @@ -434,10 +433,10 @@ func (s *KeeperTestSuite) setupTestDeposits() { ) // add deposit to cosmos zone - zone, found = quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), "cosmoshub-4") - s.Require().True(found) + zone, found = quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), "cosmoshub-4") + suite.Require().True(found) - s.addReceipt( + suite.addReceipt( &zone, testAddress, "testTxHash01", @@ -445,10 +444,10 @@ func (s *KeeperTestSuite) setupTestDeposits() { ) // add deposit to osmosis zone - zone, found = quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), "osmosis-1") - s.Require().True(found) + zone, found = quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), "osmosis-1") + suite.Require().True(found) - s.addReceipt( + suite.addReceipt( &zone, testAddress, "testTxHash02", @@ -456,18 +455,22 @@ func (s *KeeperTestSuite) setupTestDeposits() { ) } -func (s *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, coins sdk.Coins) { +func (suite *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, coins sdk.Coins) { + t := time.Now().Add(-time.Hour) + t2 := time.Now().Add(-5 * time.Minute) receipt := icstypes.Receipt{ - ChainId: zone.ChainId, - Sender: sender, - Txhash: hash, - Amount: coins, + ChainId: zone.ChainId, + Sender: sender, + Txhash: hash, + Amount: coins, + FirstSeen: &t, + Completed: &t2, } - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetReceipt(s.chainA.GetContext(), receipt) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetReceipt(suite.chainA.GetContext(), receipt) - delegationAddress := utils.GenerateAccAddressForTestWithPrefix("cosmos") - validatorAddress := utils.GenerateValAddressForTestWithPrefix("cosmos") + delegationAddress := addressutils.GenerateAddressForTestWithPrefix("cosmos") + validatorAddress := addressutils.GenerateAddressForTestWithPrefix("cosmos") delegation := icstypes.Delegation{ DelegationAddress: delegationAddress, ValidatorAddress: validatorAddress, @@ -475,18 +478,18 @@ func (s *KeeperTestSuite) addReceipt(zone *icstypes.Zone, sender, hash string, c Height: 1, RedelegationEnd: 101, } - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetDelegation(s.chainA.GetContext(), zone, delegation) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetDelegation(suite.chainA.GetContext(), zone, delegation) } -func (s *KeeperTestSuite) setupTestIntents() { - quicksilver := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) setupTestIntents() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) // chainB - zone, found := quicksilver.InterchainstakingKeeper.GetZone(s.chainA.GetContext(), s.chainB.ChainID) - s.Require().True(found) - vals := quicksilver.InterchainstakingKeeper.GetValidators(s.chainA.GetContext(), s.chainB.ChainID) + zone, found := quicksilver.InterchainstakingKeeper.GetZone(suite.chainA.GetContext(), suite.chainB.ChainID) + suite.Require().True(found) + vals := quicksilver.InterchainstakingKeeper.GetValidators(suite.chainA.GetContext(), suite.chainB.ChainID) - s.addIntent( + suite.addIntent( testAddress, zone, icstypes.ValidatorIntents{ @@ -506,17 +509,17 @@ func (s *KeeperTestSuite) setupTestIntents() { ) } -func (s *KeeperTestSuite) addIntent(address string, zone icstypes.Zone, intents icstypes.ValidatorIntents) { +func (suite *KeeperTestSuite) addIntent(address string, zone icstypes.Zone, intents icstypes.ValidatorIntents) { intent := icstypes.DelegatorIntent{ Delegator: address, Intents: intents, } - s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetDelegatorIntent(s.chainA.GetContext(), &zone, intent, false) + suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetDelegatorIntent(suite.chainA.GetContext(), &zone, intent, false) } -func (s *KeeperTestSuite) setupTestClaims() { +func (suite *KeeperTestSuite) setupTestClaims() { // add some claims - s.addClaim( + suite.addClaim( testAddress, "cosmoshub-4", cmtypes.ClaimTypeLiquidToken, @@ -524,7 +527,7 @@ func (s *KeeperTestSuite) setupTestClaims() { 40000000, ) - s.addClaim( + suite.addClaim( "quick16pxh2v4hr28h2gkntgfk8qgh47pfmjfhzgeure", "cosmoshub-4", cmtypes.ClaimTypeLiquidToken, @@ -533,7 +536,7 @@ func (s *KeeperTestSuite) setupTestClaims() { ) } -func (s *KeeperTestSuite) addClaim(address, chainID string, claimType cmtypes.ClaimType, sourceChainID string, amount uint64) { +func (suite *KeeperTestSuite) addClaim(address, chainID string, claimType cmtypes.ClaimType, sourceChainID string, amount uint64) { claim := cmtypes.Claim{ UserAddress: address, ChainId: chainID, @@ -541,5 +544,5 @@ func (s *KeeperTestSuite) addClaim(address, chainID string, claimType cmtypes.Cl SourceChainId: sourceChainID, Amount: amount, } - s.GetQuicksilverApp(s.chainA).ClaimsManagerKeeper.SetClaim(s.chainA.GetContext(), &claim) + suite.GetQuicksilverApp(suite.chainA).ClaimsManagerKeeper.SetClaim(suite.chainA.GetContext(), &claim) } diff --git a/x/participationrewards/keeper/msg_server_test.go b/x/participationrewards/keeper/msg_server_test.go index c306ae827..d598622ee 100644 --- a/x/participationrewards/keeper/msg_server_test.go +++ b/x/participationrewards/keeper/msg_server_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "encoding/json" - "fmt" "time" "cosmossdk.io/math" @@ -15,14 +14,15 @@ import ( "github.com/ingenuity-build/quicksilver/app" osmolockup "github.com/ingenuity-build/quicksilver/osmosis-types/lockup" "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/keeper" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { +func (suite *KeeperTestSuite) Test_msgServer_SubmitClaim() { // TODO: these tests ought to validate the error received. - appA := s.GetQuicksilverApp(s.chainA) + appA := suite.GetQuicksilverApp(suite.chainA) msg := types.MsgSubmitClaim{} tests := []struct { @@ -41,9 +41,9 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { "invalid_height", func() { msg = types.MsgSubmitClaim{ - UserAddress: utils.GenerateAccAddressForTest().String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainB.ChainID, + UserAddress: addressutils.GenerateAccAddressForTest().String(), + Zone: suite.chainB.ChainID, + SrcZone: suite.chainB.ChainID, ClaimType: cmtypes.ClaimTypeOsmosisPool, Proofs: []*cmtypes.Proof{ { @@ -62,8 +62,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "invalid_osmosis_user", func() { - userAddress := utils.GenerateAccAddressForTest() - osmoAddress := utils.GenerateAccAddressForTestWithPrefix("osmo") + userAddress := addressutils.GenerateAccAddressForTest() + osmoAddress := addressutils.GenerateAddressForTestWithPrefix("osmo") lockedResp := osmolockup.LockedResponse{ Lock: &osmolockup.PeriodLock{ ID: 1, @@ -78,7 +78,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { }, } bz, err := lockedResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: userAddress.String(), @@ -102,8 +102,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "invalid_osmosis_pool", func() { - userAddress := utils.GenerateAccAddressForTest() - osmoAddress := utils.ConvertAccAddressForTestUsingPrefix(userAddress, "osmo") + userAddress := addressutils.GenerateAccAddressForTest() + osmoAddress := addressutils.MustEncodeAddressToBech32("osmo", userAddress) lockedResp := osmolockup.LockedResponse{ Lock: &osmolockup.PeriodLock{ ID: 1, @@ -118,7 +118,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { }, } bz, err := lockedResp.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: userAddress.String(), @@ -142,8 +142,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "valid_osmosis", func() { - userAddress := utils.GenerateAccAddressForTest() - osmoAddress := utils.ConvertAccAddressForTestUsingPrefix(userAddress, "osmo") + userAddress := addressutils.GenerateAccAddressForTest() + osmoAddress := addressutils.MustEncodeAddressToBech32("osmo", userAddress) locked := &osmolockup.PeriodLock{ ID: 1, Owner: osmoAddress, @@ -156,7 +156,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { ), } bz, err := locked.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: userAddress.String(), @@ -180,7 +180,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "valid_liquid", func() { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3")) cd := sdk.Coin{ @@ -188,7 +188,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { Amount: math.NewInt(0), } bz, err := cd.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: address.String(), @@ -212,7 +212,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { { "valid_liquid", func() { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3")) cd := sdk.Coin{ @@ -220,7 +220,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { Amount: math.NewInt(0), } bz, err := cd.Marshal() - s.Require().NoError(err) + suite.Require().NoError(err) msg = types.MsgSubmitClaim{ UserAddress: address.String(), @@ -245,9 +245,9 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() - ctx := s.chainA.GetContext() + ctx := suite.chainA.GetContext() params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true appA.ParticipationRewardsKeeper.SetParams(ctx, params) @@ -255,21 +255,21 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitClaim() { k := keeper.NewMsgServerImpl(appA.ParticipationRewardsKeeper) resp, err := k.SubmitClaim(sdk.WrapSDKContext(ctx), &msg) if tt.wantErr != "" { - s.Require().Errorf(err, tt.wantErr) - s.Require().Nil(resp) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.wantErr) + suite.Require().Nil(resp) + suite.T().Logf("Error: %v", err) return } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.want, resp) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.want, resp) }) } } -func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { - address := utils.GenerateAccAddressForTest() +func (suite *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { + address := addressutils.GenerateAccAddressForTest() var msg *types.MsgSubmitClaim tests := []struct { @@ -284,7 +284,7 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { "local_callback_nil", func(ctx sdk.Context, appA *app.Quicksilver) {}, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { - address := utils.GenerateAccAddressForTest() + address := addressutils.GenerateAccAddressForTest() key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3")) query := abci.RequestQuery{ @@ -298,8 +298,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -319,8 +319,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_invalid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) }, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("uqatom")) @@ -336,8 +336,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -357,20 +357,22 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { { "local_callback_value_valid_denom", func(ctx sdk.Context, appA *app.Quicksilver) { - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", address, sdk.NewCoins(sdk.NewCoin("uqatom", sdk.NewInt(100))))) // add uqatom to the list of allowed denoms for this zone - blob, err := json.Marshal(types.LiquidAllowedDenomProtocolData{ - ChainID: s.chainA.ChainID, + rawPd := types.LiquidAllowedDenomProtocolData{ + ChainID: suite.chainA.ChainID, IbcDenom: "uqatom", QAssetDenom: "uqatom", - RegisteredZoneChainID: s.chainB.ChainID, - }) - s.Require().NoError(err) + RegisteredZoneChainID: suite.chainB.ChainID, + } + + blob, err := json.Marshal(rawPd) + suite.Require().NoError(err) pd := types.NewProtocolData(types.ProtocolDataType_name[int32(types.ProtocolDataTypeLiquidToken)], blob) - appA.ParticipationRewardsKeeper.SetProtocolData(ctx, fmt.Sprintf("%s/uqatom", s.chainA.ChainID), pd) + appA.ParticipationRewardsKeeper.SetProtocolData(ctx, rawPd.GenerateKey(), pd) }, func(ctx sdk.Context, appA *app.Quicksilver) *types.MsgSubmitClaim { key := banktypes.CreatePrefixedAccountStoreKey(address, []byte("uqatom")) @@ -386,8 +388,8 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { return &types.MsgSubmitClaim{ UserAddress: address.String(), - Zone: s.chainB.ChainID, - SrcZone: s.chainA.ChainID, + Zone: suite.chainB.ChainID, + SrcZone: suite.chainA.ChainID, ClaimType: cmtypes.ClaimTypeLiquidToken, Proofs: []*cmtypes.Proof{ { @@ -404,9 +406,9 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { "", []cmtypes.Claim{{ UserAddress: address.String(), - ChainId: s.chainB.ChainID, + ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, - SourceChainId: s.chainA.ChainID, + SourceChainId: suite.chainA.ChainID, Amount: 100, }}, }, @@ -414,23 +416,23 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() + suite.Run(tt.name, func() { + suite.SetupTest() - appA := s.GetQuicksilverApp(s.chainA) + appA := suite.GetQuicksilverApp(suite.chainA) // override disabled proof verification; lets test actual proofs :) appA.ParticipationRewardsKeeper.ValidateProofOps = utils.ValidateProofOps appA.ParticipationRewardsKeeper.ValidateSelfProofOps = utils.ValidateSelfProofOps - s.coordinator.CommitNBlocks(s.chainA, 3) - ctx := s.chainA.GetContext() + suite.coordinator.CommitNBlocks(suite.chainA, 3) + ctx := suite.chainA.GetContext() tt.malleate(ctx, appA) - s.coordinator.CommitNBlocks(s.chainA, 3) - ctx = s.chainA.GetContext() - s.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) - s.coordinator.CommitNBlocks(s.chainA, 1) + suite.coordinator.CommitNBlocks(suite.chainA, 3) + ctx = suite.chainA.GetContext() + suite.Require().NoError(appA.ClaimsManagerKeeper.StoreSelfConsensusState(ctx, "epoch")) + suite.coordinator.CommitNBlocks(suite.chainA, 1) - ctx = s.chainA.GetContext() + ctx = suite.chainA.GetContext() msg = tt.generate(ctx, appA) params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true @@ -440,22 +442,22 @@ func (s *KeeperTestSuite) Test_msgServer_SubmitLocalClaim() { k := keeper.NewMsgServerImpl(appA.ParticipationRewardsKeeper) resp, err := k.SubmitClaim(sdk.WrapSDKContext(ctx), msg) if tt.wantErr != "" { - s.Require().Errorf(err, tt.wantErr) - s.Require().Nil(resp) - s.T().Logf("Error: %v", err) + suite.Require().Errorf(err, tt.wantErr) + suite.Require().Nil(resp) + suite.T().Logf("Error: %v", err) return } for _, expectedClaim := range tt.claims { actualClaim, found := appA.ClaimsManagerKeeper.GetClaim(ctx, expectedClaim.ChainId, expectedClaim.UserAddress, expectedClaim.Module, expectedClaim.SourceChainId) - s.Require().True(found) - s.Require().Equal(expectedClaim.Amount, actualClaim.Amount) + suite.Require().True(found) + suite.Require().Equal(expectedClaim.Amount, actualClaim.Amount) } - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tt.want, resp) + suite.Require().NoError(err) + suite.Require().NotNil(resp) + suite.Require().Equal(tt.want, resp) }) } } diff --git a/x/participationrewards/keeper/proposal_handler.go b/x/participationrewards/keeper/proposal_handler.go index 628718627..898c8dc58 100644 --- a/x/participationrewards/keeper/proposal_handler.go +++ b/x/participationrewards/keeper/proposal_handler.go @@ -28,7 +28,7 @@ func HandleAddProtocolDataProposal(ctx sdk.Context, k *Keeper, p *types.AddProto return err } - k.SetProtocolData(ctx, p.Key, protocolData) + k.SetProtocolData(ctx, pd.GenerateKey(), protocolData) return nil } diff --git a/x/participationrewards/keeper/proposal_handler_test.go b/x/participationrewards/keeper/proposal_handler_test.go index 742c80024..c36641da7 100644 --- a/x/participationrewards/keeper/proposal_handler_test.go +++ b/x/participationrewards/keeper/proposal_handler_test.go @@ -7,8 +7,8 @@ import ( "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) TestHandleAddProtocolDataProposal() { - appA := s.GetQuicksilverApp(s.chainA) +func (suite *KeeperTestSuite) TestHandleAddProtocolDataProposal() { + appA := suite.GetQuicksilverApp(suite.chainA) prop := types.AddProtocolDataProposal{} tests := []struct { @@ -78,7 +78,7 @@ func (s *KeeperTestSuite) TestHandleAddProtocolDataProposal() { { "valid_prop", func() { - connpdstr := fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d, \"prefix\": \"cosmos\"}", s.path.EndpointB.ConnectionID, s.chainB.ChainID, 0) + connpdstr := fmt.Sprintf("{\"connectionid\": %q,\"chainid\": %q,\"lastepoch\": %d, \"prefix\": \"cosmos\"}", suite.path.EndpointB.ConnectionID, suite.chainB.ChainID, 0) prop = types.AddProtocolDataProposal{ Title: "Add connection protocol for test chain B", @@ -92,17 +92,17 @@ func (s *KeeperTestSuite) TestHandleAddProtocolDataProposal() { }, } for _, tt := range tests { - s.Run(tt.name, func() { + suite.Run(tt.name, func() { tt.malleate() k := appA.ParticipationRewardsKeeper - err := keeper.HandleAddProtocolDataProposal(s.chainA.GetContext(), k, &prop) + err := keeper.HandleAddProtocolDataProposal(suite.chainA.GetContext(), k, &prop) if tt.wantErr { - s.Require().Error(err) - s.T().Logf("Error: %v", err) + suite.Require().Error(err) + suite.T().Logf("Error: %v", err) return } - s.Require().NoError(err) + suite.Require().NoError(err) }) } } diff --git a/x/participationrewards/keeper/protocol_data.go b/x/participationrewards/keeper/protocol_data.go index a6384f84a..3a16b44c1 100644 --- a/x/participationrewards/keeper/protocol_data.go +++ b/x/participationrewards/keeper/protocol_data.go @@ -11,7 +11,7 @@ import ( func (k *Keeper) GetProtocolData(ctx sdk.Context, pdType types.ProtocolDataType, key string) (types.ProtocolData, bool) { data := types.ProtocolData{} store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProtocolData) - bz := store.Get(types.GetProtocolDataKey(pdType, key)) + bz := store.Get(types.GetProtocolDataKey(pdType, []byte(key))) if len(bz) == 0 { return data, false } @@ -20,8 +20,8 @@ func (k *Keeper) GetProtocolData(ctx sdk.Context, pdType types.ProtocolDataType, return data, true } -// SetProtocolData sets protocol data info. -func (k *Keeper) SetProtocolData(ctx sdk.Context, key string, data *types.ProtocolData) { +// SetProtocolData set protocol data info. +func (k Keeper) SetProtocolData(ctx sdk.Context, key []byte, data *types.ProtocolData) { if data == nil { k.Logger(ctx).Error("protocol data not set; value is nil") return @@ -39,13 +39,13 @@ func (k *Keeper) SetProtocolData(ctx sdk.Context, key string, data *types.Protoc } // DeleteProtocolData deletes protocol data info. -func (k *Keeper) DeleteProtocolData(ctx sdk.Context, key string) { +func (k *Keeper) DeleteProtocolData(ctx sdk.Context, key []byte) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProtocolData) - store.Delete([]byte(key)) + store.Delete(key) } // IteratePrefixedProtocolDatas iterate through protocol data with the given prefix and perform the provided function. -func (k *Keeper) IteratePrefixedProtocolDatas(ctx sdk.Context, key []byte, fn func(index int64, data types.ProtocolData) (stop bool)) { +func (k *Keeper) IteratePrefixedProtocolDatas(ctx sdk.Context, key []byte, fn func(index int64, key []byte, data types.ProtocolData) (stop bool)) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixProtocolData) iterator := sdk.KVStorePrefixIterator(store, key) defer iterator.Close() @@ -54,7 +54,7 @@ func (k *Keeper) IteratePrefixedProtocolDatas(ctx sdk.Context, key []byte, fn fu for ; iterator.Valid(); iterator.Next() { data := types.ProtocolData{} k.cdc.MustUnmarshal(iterator.Value(), &data) - stop := fn(i, data) + stop := fn(i, iterator.Key(), data) if stop { break } diff --git a/x/participationrewards/keeper/rewards_holdings_test.go b/x/participationrewards/keeper/rewards_holdings_test.go index 9ad301c4b..dc70d95cd 100644 --- a/x/participationrewards/keeper/rewards_holdings_test.go +++ b/x/participationrewards/keeper/rewards_holdings_test.go @@ -5,14 +5,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/app" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) -func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { - user1 := utils.GenerateAccAddressForTest() - user2 := utils.GenerateAccAddressForTest() +func (suite *KeeperTestSuite) TestCalcUserHoldingsAllocations() { + user1 := addressutils.GenerateAccAddressForTest() + user2 := addressutils.GenerateAccAddressForTest() tests := []struct { name string @@ -24,7 +24,7 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "zero claims; no allocation", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 0 appA.InterchainstakingKeeper.SetZone(ctx, &zone) }, @@ -35,11 +35,11 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "zero relevant claims; 64k allocation, all returned", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 64000 appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 1000}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: "otherchain-1", Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 1000}) }, []types.UserAllocation{}, sdk.NewInt(64000), @@ -48,13 +48,13 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "valid claims - equal claims", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 5000 - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(5000))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(5000))))) appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 2500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 2500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 2500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 2500}) }, []types.UserAllocation{ { @@ -72,13 +72,13 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "valid claims - inequal claims, less than 100%, truncation", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 5000 - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(2500))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(2500))))) appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 1000}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 1000}) }, []types.UserAllocation{ { @@ -96,13 +96,13 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { { "valid claims - inequal claims, 100%, truncation", func(ctx sdk.Context, appA *app.Quicksilver) { - zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) + zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) zone.HoldingsAllocation = 5000 - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(1500))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(1500))))) appA.InterchainstakingKeeper.SetZone(ctx, &zone) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 500}) - appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: s.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: s.chainA.ChainID, Amount: 1000}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 500}) + appA.ClaimsManagerKeeper.SetClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: 1000}) }, []types.UserAllocation{ { @@ -121,27 +121,27 @@ func (s *KeeperTestSuite) TestCalcUserHoldingsAllocations() { for _, tt := range tests { tt := tt - s.Run(tt.name, func() { - s.SetupTest() + suite.Run(tt.name, func() { + suite.SetupTest() - appA := s.GetQuicksilverApp(s.chainA) - ctx := s.chainA.GetContext() + appA := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() params := appA.ParticipationRewardsKeeper.GetParams(ctx) params.ClaimsEnabled = true appA.ParticipationRewardsKeeper.SetParams(ctx, params) - tt.malleate(s.chainA.GetContext(), appA) + tt.malleate(suite.chainA.GetContext(), appA) - zone, found := appA.InterchainstakingKeeper.GetZone(ctx, s.chainB.ChainID) - s.Require().True(found) + zone, found := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) + suite.Require().True(found) - s.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) - s.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) + suite.Require().NoError(appA.BankKeeper.SendCoinsFromModuleToModule(ctx, "mint", types.ModuleName, sdk.NewCoins(sdk.NewCoin(appA.StakingKeeper.BondDenom(ctx), sdk.NewIntFromUint64(zone.HoldingsAllocation))))) allocations, remainder := appA.ParticipationRewardsKeeper.CalcUserHoldingsAllocations(ctx, &zone) - s.Require().ElementsMatch(tt.want, allocations) - s.Require().True(tt.remainder.Equal(remainder)) + suite.Require().ElementsMatch(tt.want, allocations) + suite.Require().True(tt.remainder.Equal(remainder)) }) } } diff --git a/x/participationrewards/keeper/submodule_liquid.go b/x/participationrewards/keeper/submodule_liquid.go index a755b3a87..bb6d15b48 100644 --- a/x/participationrewards/keeper/submodule_liquid.go +++ b/x/participationrewards/keeper/submodule_liquid.go @@ -55,7 +55,7 @@ func (m *LiquidTokensModule) ValidateClaim(ctx sdk.Context, k *Keeper, msg *type return 0, err } - data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeLiquidToken, fmt.Sprintf("%s/%s", msg.SrcZone, denom)) + data, found := k.GetProtocolData(ctx, types.ProtocolDataTypeLiquidToken, fmt.Sprintf("%s_%s", msg.SrcZone, denom)) if !found { // we don't have a record for this denom, but this is okay, we don't want to submit records for every ibc denom. continue diff --git a/x/participationrewards/keeper/submodule_osmosis.go b/x/participationrewards/keeper/submodule_osmosis.go index 186de49fb..4dc40858f 100644 --- a/x/participationrewards/keeper/submodule_osmosis.go +++ b/x/participationrewards/keeper/submodule_osmosis.go @@ -43,7 +43,7 @@ func (m *OsmosisModule) Hooks(ctx sdk.Context, k *Keeper) { return } - k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, data types.ProtocolData) bool { + k.IteratePrefixedProtocolDatas(ctx, types.GetPrefixProtocolDataKey(types.ProtocolDataTypeOsmosisPool), func(idx int64, _ []byte, data types.ProtocolData) bool { ipool, err := types.UnmarshalProtocolData(types.ProtocolDataTypeOsmosisPool, data.Data) if err != nil { return false diff --git a/x/participationrewards/types/errors.go b/x/participationrewards/types/errors.go index 6cb17c846..ad03eeaeb 100644 --- a/x/participationrewards/types/errors.go +++ b/x/participationrewards/types/errors.go @@ -14,4 +14,6 @@ var ( ErrNothingToAllocate = sdkioerrors.Register(ModuleName, 9, "balance is zero, nothing to allocate") ErrInvalidAssetName = sdkioerrors.Register(ModuleName, 10, "invalid ibc asset name") ErrInvalidChainID = sdkioerrors.Register(ModuleName, 11, "invalid chain id") + ErrInvalidDenom = sdkioerrors.Register(ModuleName, 12, "invalid denom") + ErrCannotUnmarshal = sdkioerrors.Register(ModuleName, 13, "unable to unmarshal") ) diff --git a/x/participationrewards/types/keys.go b/x/participationrewards/types/keys.go index ddd4ce106..4ab00fd0f 100644 --- a/x/participationrewards/types/keys.go +++ b/x/participationrewards/types/keys.go @@ -19,8 +19,8 @@ const ( var KeyPrefixProtocolData = []byte{0x00} -func GetProtocolDataKey(pdType ProtocolDataType, key string) []byte { - return append(sdk.Uint64ToBigEndian(uint64(pdType)), []byte(key)...) +func GetProtocolDataKey(pdType ProtocolDataType, key []byte) []byte { + return append(sdk.Uint64ToBigEndian(uint64(pdType)), key...) } func GetPrefixProtocolDataKey(pdType ProtocolDataType) []byte { diff --git a/x/participationrewards/types/messages.pb.go b/x/participationrewards/types/messages.pb.go index 279676952..1329f7893 100644 --- a/x/participationrewards/types/messages.pb.go +++ b/x/participationrewards/types/messages.pb.go @@ -121,36 +121,36 @@ func init() { } var fileDescriptor_b87e3ea017f90b50 = []byte{ - // 453 bytes of a gzipped FileDescriptorProto + // 454 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x31, 0x6f, 0xd3, 0x40, - 0x1c, 0xc5, 0x7d, 0x49, 0xa9, 0xca, 0x15, 0x75, 0xb0, 0x2a, 0x64, 0x22, 0xe4, 0x46, 0xe9, 0x40, + 0x14, 0xc7, 0x7d, 0x49, 0xa9, 0xca, 0x15, 0x75, 0xb0, 0x2a, 0x64, 0x22, 0xe4, 0x46, 0xe9, 0x40, 0x84, 0x14, 0x1f, 0x71, 0x17, 0xd4, 0xb2, 0xd0, 0x0e, 0x4c, 0x95, 0x90, 0xcb, 0x84, 0x84, 0xa2, - 0x8b, 0x73, 0x1c, 0x27, 0xe2, 0xbb, 0xe3, 0xfe, 0x67, 0xd3, 0x30, 0x32, 0x31, 0x21, 0x24, 0xbe, - 0x40, 0x3f, 0x04, 0x0b, 0x23, 0x1b, 0x63, 0x05, 0x0b, 0x23, 0x4a, 0x18, 0xf8, 0x18, 0xc8, 0xe7, - 0x04, 0xd9, 0x52, 0x84, 0x50, 0xb7, 0xbb, 0xe7, 0xff, 0xef, 0xef, 0xa7, 0xf7, 0x0e, 0xc7, 0xaf, - 0x72, 0x91, 0xbe, 0x04, 0x31, 0x2d, 0x98, 0x21, 0x9a, 0x1a, 0x2b, 0x52, 0xa1, 0xa9, 0x15, 0x4a, - 0x1a, 0xf6, 0x9a, 0x9a, 0x09, 0x90, 0x62, 0x48, 0x32, 0x06, 0x40, 0x39, 0x83, 0x48, 0x1b, 0x65, - 0x95, 0xbf, 0x5f, 0x63, 0xa2, 0x75, 0x4c, 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 0xbf, + 0xca, 0x45, 0xfa, 0x12, 0xc4, 0xb4, 0x60, 0x86, 0x68, 0x6a, 0xac, 0x48, 0x85, 0xa6, 0x56, 0x28, + 0x69, 0xd8, 0x6b, 0x6a, 0x26, 0x40, 0x8a, 0x21, 0xc9, 0x18, 0x00, 0xe5, 0x0c, 0x22, 0x6d, 0x94, + 0x55, 0xfe, 0x7e, 0x8d, 0x89, 0xd6, 0x31, 0x51, 0x31, 0xec, 0xdc, 0x4a, 0x15, 0x64, 0x0a, 0x46, + 0x0e, 0x21, 0xd5, 0xa5, 0xe2, 0x3b, 0xbb, 0x5c, 0x71, 0x55, 0xe9, 0xe5, 0x69, 0xa9, 0xde, 0xe6, + 0x4a, 0xf1, 0x29, 0x23, 0x54, 0x0b, 0x42, 0xa5, 0x54, 0xd6, 0x75, 0x5c, 0x31, 0xf7, 0xea, 0x3e, + 0xd3, 0x29, 0x15, 0x19, 0x64, 0x54, 0x52, 0xce, 0x4c, 0x69, 0xb0, 0x21, 0x54, 0x44, 0xef, 0x7d, + 0x0b, 0xef, 0x9c, 0x02, 0x3f, 0xcb, 0xc7, 0x99, 0xb0, 0x27, 0x65, 0x81, 0xff, 0x00, 0xdf, 0xc8, + 0x81, 0x99, 0x11, 0x9d, 0x4c, 0x0c, 0x03, 0x08, 0x50, 0x17, 0xf5, 0xaf, 0x1f, 0x07, 0xdf, 0x3e, + 0x0d, 0x76, 0x97, 0x06, 0x1f, 0x56, 0x5f, 0xce, 0xac, 0x11, 0x92, 0x27, 0x8d, 0x6a, 0xdf, 0xc7, + 0x1b, 0x6f, 0x94, 0x64, 0x41, 0xab, 0xa4, 0x12, 0x77, 0xf6, 0x3b, 0x78, 0x0b, 0x4c, 0x3a, 0x72, + 0x7a, 0xdb, 0xe9, 0x7f, 0xef, 0xfe, 0x23, 0x8c, 0x9d, 0xaf, 0x91, 0x9d, 0x69, 0x16, 0x6c, 0x74, + 0x51, 0x7f, 0x27, 0xbe, 0x13, 0xd5, 0x67, 0xd7, 0xb4, 0x5d, 0x0c, 0x23, 0x67, 0xf3, 0xc9, 0x4c, + 0xb3, 0xa4, 0x86, 0xfa, 0x47, 0x78, 0x53, 0x1b, 0xa5, 0x9e, 0x43, 0x70, 0xad, 0xdb, 0xee, 0x6f, + 0xc7, 0xfb, 0xff, 0x6e, 0xf2, 0xb8, 0xac, 0x4d, 0x96, 0xc8, 0xe1, 0xd6, 0xbb, 0x8b, 0x3d, 0xef, + 0xf7, 0xc5, 0x9e, 0xd7, 0x0b, 0xf0, 0xcd, 0xe6, 0x3c, 0x12, 0x06, 0x5a, 0x49, 0x60, 0xf1, 0x17, + 0x84, 0xdb, 0xa7, 0xc0, 0xfd, 0xcf, 0x08, 0x6f, 0xd7, 0xe7, 0x75, 0x10, 0xfd, 0x47, 0xd2, 0x51, + 0xb3, 0x69, 0xe7, 0xe8, 0x0a, 0xd0, 0xca, 0x49, 0xef, 0xfe, 0xdb, 0xef, 0xbf, 0x3e, 0xb6, 0xe2, + 0xde, 0x80, 0xd4, 0xf3, 0xb6, 0xe7, 0x65, 0xc8, 0x6b, 0xb7, 0xd3, 0xfd, 0xfd, 0x21, 0xba, 0x7b, + 0xfc, 0xec, 0xeb, 0x3c, 0x44, 0x97, 0xf3, 0x10, 0xfd, 0x9c, 0x87, 0xe8, 0xc3, 0x22, 0xf4, 0x2e, + 0x17, 0xa1, 0xf7, 0x63, 0x11, 0x7a, 0x4f, 0x4f, 0xb8, 0xb0, 0x2f, 0xf2, 0x71, 0x94, 0xaa, 0x8c, + 0x08, 0xc9, 0x99, 0xcc, 0x85, 0x9d, 0x0d, 0xc6, 0xb9, 0x98, 0x4e, 0x1a, 0xaf, 0x9c, 0xaf, 0x7f, + 0xa1, 0x8c, 0x00, 0xc6, 0x9b, 0x6e, 0xa9, 0x0e, 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x30, 0xbc, + 0x8e, 0x07, 0x30, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/participationrewards/types/msgs_test.go b/x/participationrewards/types/msgs_test.go index 9b69ce951..1637935d0 100644 --- a/x/participationrewards/types/msgs_test.go +++ b/x/participationrewards/types/msgs_test.go @@ -9,13 +9,13 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/proto/tendermint/crypto" - "github.com/ingenuity-build/quicksilver/utils" + "github.com/ingenuity-build/quicksilver/utils/addressutils" cmtypes "github.com/ingenuity-build/quicksilver/x/claimsmanager/types" "github.com/ingenuity-build/quicksilver/x/participationrewards/types" ) func TestMsgSubmitClaim_ValidateBasic(t *testing.T) { - userAddress := utils.GenerateAccAddressForTest().String() + userAddress := addressutils.GenerateAccAddressForTest().String() type fields struct { UserAddress string @@ -106,7 +106,7 @@ func TestMsgSubmitClaim_ValidateBasic(t *testing.T) { } func TestMsgSubmitClaim_GetSigners(t *testing.T) { - validAddress := utils.GenerateAccAddressForTest().String() + validAddress := addressutils.GenerateAccAddressForTest().String() validAcc, _ := sdk.AccAddressFromBech32(validAddress) type fields struct { @@ -150,7 +150,7 @@ func TestMsgSubmitClaim_GetSigners(t *testing.T) { } func TestNewMsgSubmitClaim(t *testing.T) { - userAddress := utils.GenerateAccAddressForTest() + userAddress := addressutils.GenerateAccAddressForTest() type args struct { userAddress sdk.Address srcZone string diff --git a/x/participationrewards/types/params.go b/x/participationrewards/types/params.go index 10ba5a856..72b1ffe73 100644 --- a/x/participationrewards/types/params.go +++ b/x/participationrewards/types/params.go @@ -58,13 +58,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { } } -// ParamSetPairs implements params.ParamSet. -func (p *ParamsV1) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyDistributionProportions, &p.DistributionProportions, validateDistributionProportions), - } -} - func validateDistributionProportions(i interface{}) error { dp, ok := i.(DistributionProportions) if !ok { @@ -93,12 +86,3 @@ func (p *Params) String() string { out, _ := yaml.Marshal(p) return string(out) } - -// String implements the Stringer interface. -func (p *ParamsV1) String() string { - out, err := yaml.Marshal(p) - if err != nil { - panic(err) - } - return string(out) -} diff --git a/x/participationrewards/types/participationrewards.pb.go b/x/participationrewards/types/participationrewards.pb.go index 62e9c2936..8de13c59a 100644 --- a/x/participationrewards/types/participationrewards.pb.go +++ b/x/participationrewards/types/participationrewards.pb.go @@ -108,45 +108,6 @@ func (m *DistributionProportions) XXX_DiscardUnknown() { var xxx_messageInfo_DistributionProportions proto.InternalMessageInfo -// Params holds parameters for the participationrewards module. -type ParamsV1 struct { - // distribution_proportions defines the proportions of the minted - // participation rewards; - DistributionProportions DistributionProportions `protobuf:"bytes,1,opt,name=distribution_proportions,json=distributionProportions,proto3" json:"distribution_proportions"` -} - -func (m *ParamsV1) Reset() { *m = ParamsV1{} } -func (*ParamsV1) ProtoMessage() {} -func (*ParamsV1) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{1} -} -func (m *ParamsV1) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ParamsV1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ParamsV1.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ParamsV1) XXX_Merge(src proto.Message) { - xxx_messageInfo_ParamsV1.Merge(m, src) -} -func (m *ParamsV1) XXX_Size() int { - return m.Size() -} -func (m *ParamsV1) XXX_DiscardUnknown() { - xxx_messageInfo_ParamsV1.DiscardUnknown(m) -} - -var xxx_messageInfo_ParamsV1 proto.InternalMessageInfo - // Params holds parameters for the participationrewards module. type Params struct { // distribution_proportions defines the proportions of the minted @@ -158,7 +119,7 @@ type Params struct { func (m *Params) Reset() { *m = Params{} } func (*Params) ProtoMessage() {} func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{2} + return fileDescriptor_d4fb4e5bb851c124, []int{1} } func (m *Params) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -196,7 +157,7 @@ func (m *KeyedProtocolData) Reset() { *m = KeyedProtocolData{} } func (m *KeyedProtocolData) String() string { return proto.CompactTextString(m) } func (*KeyedProtocolData) ProtoMessage() {} func (*KeyedProtocolData) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{3} + return fileDescriptor_d4fb4e5bb851c124, []int{2} } func (m *KeyedProtocolData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -250,7 +211,7 @@ func (m *ProtocolData) Reset() { *m = ProtocolData{} } func (m *ProtocolData) String() string { return proto.CompactTextString(m) } func (*ProtocolData) ProtoMessage() {} func (*ProtocolData) Descriptor() ([]byte, []int) { - return fileDescriptor_d4fb4e5bb851c124, []int{4} + return fileDescriptor_d4fb4e5bb851c124, []int{3} } func (m *ProtocolData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -296,7 +257,6 @@ func (m *ProtocolData) GetData() encoding_json.RawMessage { func init() { proto.RegisterEnum("quicksilver.participationrewards.v1.ProtocolDataType", ProtocolDataType_name, ProtocolDataType_value) proto.RegisterType((*DistributionProportions)(nil), "quicksilver.participationrewards.v1.DistributionProportions") - proto.RegisterType((*ParamsV1)(nil), "quicksilver.participationrewards.v1.Params_v1") proto.RegisterType((*Params)(nil), "quicksilver.participationrewards.v1.Params") proto.RegisterType((*KeyedProtocolData)(nil), "quicksilver.participationrewards.v1.KeyedProtocolData") proto.RegisterType((*ProtocolData)(nil), "quicksilver.participationrewards.v1.ProtocolData") @@ -307,47 +267,46 @@ func init() { } var fileDescriptor_d4fb4e5bb851c124 = []byte{ - // 636 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x54, 0xc1, 0x4f, 0xd4, 0x4e, - 0x14, 0x6e, 0x97, 0xfe, 0x08, 0x0c, 0xf0, 0x4b, 0x19, 0x4d, 0x80, 0x15, 0xba, 0x88, 0xd1, 0x18, - 0x13, 0x5a, 0x17, 0x6f, 0x84, 0x98, 0xb8, 0xac, 0x27, 0x35, 0x92, 0x82, 0x1e, 0x4c, 0x4c, 0x33, - 0x3b, 0x33, 0x94, 0x71, 0x67, 0x67, 0x4a, 0xa7, 0x5d, 0xdc, 0x03, 0x89, 0xf1, 0xc4, 0xd1, 0x83, - 0x07, 0x8f, 0x26, 0xfe, 0x0b, 0x1e, 0xfc, 0x13, 0x38, 0x12, 0x4f, 0xc6, 0x03, 0x31, 0xf0, 0x5f, - 0x78, 0x30, 0x66, 0xda, 0x5d, 0xac, 0x6b, 0x4d, 0x38, 0x90, 0x78, 0xea, 0x9b, 0xf7, 0xbe, 0xf9, - 0xbe, 0x37, 0xfd, 0xde, 0x0c, 0xb8, 0xbb, 0x9b, 0x32, 0xdc, 0x56, 0x8c, 0x77, 0x69, 0xec, 0x45, - 0x28, 0x4e, 0x18, 0x66, 0x11, 0x4a, 0x98, 0x14, 0x31, 0xdd, 0x43, 0x31, 0x51, 0x5e, 0xb7, 0x5e, - 0x9a, 0x77, 0xa3, 0x58, 0x26, 0x12, 0x5e, 0x2b, 0xec, 0x77, 0x4b, 0x71, 0xdd, 0x7a, 0x75, 0x0e, - 0x4b, 0xd5, 0x91, 0x2a, 0xc8, 0xb6, 0x78, 0xf9, 0x22, 0xdf, 0x5f, 0xbd, 0x1c, 0xca, 0x50, 0xe6, - 0x79, 0x1d, 0xe5, 0xd9, 0xa5, 0x1f, 0x15, 0x30, 0xd3, 0x64, 0x2a, 0x89, 0x59, 0x2b, 0xd5, 0x5c, - 0x1b, 0xb1, 0x8c, 0x64, 0xac, 0x23, 0x05, 0x5f, 0x9b, 0xc0, 0xe9, 0x22, 0xce, 0x08, 0x4a, 0x64, - 0x1c, 0x28, 0xca, 0x29, 0xd6, 0x85, 0x00, 0x71, 0x2e, 0x71, 0xa6, 0x3c, 0x6b, 0x2e, 0x9a, 0x37, - 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e, 0x79, 0x74, - 0xe2, 0x98, 0xdf, 0x4e, 0x1c, 0xf3, 0xcd, 0xa9, 0x63, 0x1c, 0x9d, 0x3a, 0xc6, 0x97, 0x53, 0xc7, - 0x78, 0xb6, 0x5e, 0xb8, 0x91, 0x4c, 0x84, 0x54, 0xa4, 0x2c, 0xe9, 0x2d, 0xb7, 0x52, 0xc6, 0x89, - 0x57, 0x7c, 0x75, 0x5f, 0x96, 0xbf, 0xbb, 0xd9, 0x95, 0x6d, 0x8d, 0x66, 0x2e, 0xde, 0xf9, 0x19, - 0x00, 0x00, 0xff, 0xff, 0x16, 0x6f, 0x81, 0xb8, 0xa8, 0x05, 0x00, 0x00, + // 621 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xc1, 0x6f, 0xd3, 0x3e, + 0x14, 0x4e, 0xba, 0xfc, 0xa6, 0xfd, 0xbc, 0x0d, 0x65, 0x06, 0x69, 0x5b, 0xd9, 0xd2, 0x31, 0x04, + 0x42, 0x48, 0x4b, 0xd8, 0xb8, 0x4d, 0x13, 0x12, 0x5d, 0x39, 0x01, 0x62, 0xca, 0x0a, 0x07, 0x24, + 0x54, 0xb9, 0xb6, 0x97, 0x9a, 0xba, 0x76, 0x16, 0x27, 0x1d, 0x3d, 0x4c, 0x42, 0x9c, 0x76, 0xe4, + 0xc8, 0x11, 0x89, 0x7f, 0x81, 0x03, 0x7f, 0xc2, 0x8e, 0x13, 0x27, 0xc4, 0xa1, 0x42, 0xed, 0x7f, + 0xc1, 0x01, 0x21, 0x27, 0x6d, 0x09, 0xa5, 0x93, 0x76, 0xd8, 0x29, 0xcf, 0xcf, 0x9f, 0xbf, 0xef, + 0xf9, 0x7d, 0x2f, 0x06, 0x0f, 0x0e, 0x13, 0x86, 0x9b, 0x8a, 0xf1, 0x36, 0x8d, 0xbc, 0x10, 0x45, + 0x31, 0xc3, 0x2c, 0x44, 0x31, 0x93, 0x22, 0xa2, 0x47, 0x28, 0x22, 0xca, 0x6b, 0x6f, 0x4e, 0xcc, + 0xbb, 0x61, 0x24, 0x63, 0x09, 0x6f, 0xe6, 0xce, 0xbb, 0x13, 0x71, 0xed, 0xcd, 0xe2, 0x32, 0x96, + 0xaa, 0x25, 0x55, 0x2d, 0x3d, 0xe2, 0x65, 0x8b, 0xec, 0x7c, 0xf1, 0x5a, 0x20, 0x03, 0x99, 0xe5, + 0x75, 0x94, 0x65, 0xd7, 0x7f, 0x15, 0xc0, 0x62, 0x85, 0xa9, 0x38, 0x62, 0xf5, 0x44, 0x73, 0xed, + 0x45, 0x32, 0x94, 0x91, 0x8e, 0x14, 0x7c, 0x67, 0x02, 0xa7, 0x8d, 0x38, 0x23, 0x28, 0x96, 0x51, + 0x4d, 0x51, 0x4e, 0xb1, 0xde, 0xa8, 0x21, 0xce, 0x25, 0x4e, 0x95, 0x97, 0xcc, 0x35, 0xf3, 0xce, + 0xff, 0xe5, 0x9d, 0xd3, 0x6e, 0xc9, 0xf8, 0xde, 0x2d, 0xdd, 0x0e, 0x58, 0xdc, 0x48, 0xea, 0x2e, + 0x96, 0xad, 0x81, 0xf6, 0xe0, 0xb3, 0xa1, 0x48, 0xd3, 0x8b, 0x3b, 0x21, 0x55, 0x6e, 0x85, 0xe2, + 0xaf, 0x9f, 0x37, 0xc0, 0xa0, 0xb4, 0x0a, 0xc5, 0xfe, 0xca, 0x48, 0x63, 0x7f, 0x28, 0xf1, 0x70, + 0xa4, 0x00, 0x5b, 0xe0, 0x6a, 0x43, 0x72, 0xc2, 0x44, 0xa0, 0xf2, 0xc2, 0x85, 0x4b, 0x10, 0x86, + 0x43, 0xe2, 0x9c, 0x1c, 0x03, 0x0b, 0x5c, 0xe2, 0x66, 0x12, 0xe6, 0xc5, 0xa6, 0x2e, 0x41, 0xcc, + 0xce, 0x68, 0xff, 0x48, 0x6d, 0x5b, 0x27, 0x1f, 0x4b, 0xc6, 0xfa, 0x17, 0x13, 0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, 0x0a, 0x91, 0xcd, 0xb2, 0x6d, 0xc2, 0x1b, 0x60, 0x75, 0x7c, 0xff, 0x99, + 0x1e, 0x0c, 0xa6, 0x32, 0xe7, 0xed, 0x02, 0x2c, 0x81, 0xeb, 0xe3, 0x90, 0x27, 0xec, 0x30, 0x61, + 0xa4, 0x2a, 0x9b, 0x54, 0xd8, 0x53, 0x93, 0x00, 0x43, 0x0e, 0x29, 0xb9, 0x6d, 0xc1, 0x35, 0xb0, + 0xf2, 0x4f, 0x11, 0x11, 0x55, 0x98, 0x8a, 0x38, 0x45, 0xfc, 0x37, 0x09, 0xb1, 0xcf, 0x0e, 0x70, + 0x03, 0x31, 0x91, 0x22, 0xa6, 0x8b, 0xd6, 0xc9, 0x27, 0xc7, 0x28, 0xbf, 0x3a, 0xed, 0x39, 0xe6, + 0x59, 0xcf, 0x31, 0x7f, 0xf4, 0x1c, 0xf3, 0x7d, 0xdf, 0x31, 0xce, 0xfa, 0x8e, 0xf1, 0xad, 0xef, + 0x18, 0x2f, 0x77, 0x73, 0xa3, 0xcf, 0x44, 0x40, 0x45, 0xc2, 0xe2, 0xce, 0x46, 0x3d, 0x61, 0x9c, + 0x78, 0xf9, 0xe7, 0xed, 0xcd, 0xe4, 0x07, 0x2e, 0xfd, 0x37, 0xea, 0xd3, 0xa9, 0x8b, 0xf7, 0x7f, + 0x07, 0x00, 0x00, 0xff, 0xff, 0x6c, 0x87, 0x46, 0x1b, 0x11, 0x05, 0x00, 0x00, } func (m *DistributionProportions) Marshal() (dAtA []byte, err error) { @@ -403,39 +362,6 @@ func (m *DistributionProportions) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *ParamsV1) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ParamsV1) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ParamsV1) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.DistributionProportions.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintParticipationrewards(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -584,17 +510,6 @@ func (m *DistributionProportions) Size() (n int) { return n } -func (m *ParamsV1) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.DistributionProportions.Size() - n += 1 + l + sovParticipationrewards(uint64(l)) - return n -} - func (m *Params) Size() (n int) { if m == nil { return 0 @@ -801,89 +716,6 @@ func (m *DistributionProportions) Unmarshal(dAtA []byte) error { } return nil } -func (m *ParamsV1) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParticipationrewards - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Params_v1: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params_v1: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DistributionProportions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowParticipationrewards - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthParticipationrewards - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthParticipationrewards - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.DistributionProportions.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipParticipationrewards(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthParticipationrewards - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *Params) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/participationrewards/types/participationrewards_test.go b/x/participationrewards/types/participationrewards_test.go index 97e17c59b..d93dbdc89 100644 --- a/x/participationrewards/types/participationrewards_test.go +++ b/x/participationrewards/types/participationrewards_test.go @@ -74,16 +74,14 @@ func TestDistributionProportions_ValidateBasic(t *testing.T) { func TestKeyedProtocolData_ValidateBasic(t *testing.T) { invalidOsmosisData := `{ "poolname": "osmosispools/1", - "zones": { - "": "" - } + "denoms": { } }` validOsmosisData := `{ "poolid": 1, "poolname": "atom/osmo", "pooltype": "balancer", - "zones": { - "zone_id": "IBC/zone_denom" + "denoms": { + "uosmo": {"chainid": "osmosis-1", "denom": "uosmo"} } }` validLiquidData := `{ diff --git a/x/participationrewards/types/proposals.go b/x/participationrewards/types/proposals.go index 02a2b5f4a..c8dd7ebb0 100644 --- a/x/participationrewards/types/proposals.go +++ b/x/participationrewards/types/proposals.go @@ -36,14 +36,24 @@ func (m *AddProtocolDataProposal) ValidateBasic() error { errors["Type"] = ErrUndefinedAttribute } - if m.Key == "" { - errors["Key"] = ErrUndefinedAttribute - } + // Key is now a deprecated field and unused. + // if len(m.Key) == 0 { + // errors["Key"] = ErrUndefinedAttribute + // } if len(m.Data) == 0 { errors["Data"] = ErrUndefinedAttribute } + pd, err := UnmarshalProtocolData(ProtocolDataType(ProtocolDataType_value[m.Type]), m.Data) + if err != nil { + errors["Data"] = err + } else { + if err = pd.ValidateBasic(); err != nil { + errors["Data"] = err + } + } + if len(errors) > 0 { return multierror.New(errors) } @@ -58,6 +68,5 @@ Title: %s Description: %s Type: %s Data: %s -Key: %s -`, m.Title, m.Description, m.Type, m.Data, m.Key) +`, m.Title, m.Description, m.Type, m.Data) } diff --git a/x/participationrewards/types/proposals_test.go b/x/participationrewards/types/proposals_test.go index 3df195a4a..17cb72b3f 100644 --- a/x/participationrewards/types/proposals_test.go +++ b/x/participationrewards/types/proposals_test.go @@ -55,7 +55,6 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Description: "A new protocol for testing protocols", Protocol: "TestProtocol", Type: "", - Key: "", Data: nil, }, true, @@ -67,7 +66,6 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Description: "A new protocol for testing protocols", Protocol: "TestProtocol", Type: "TestType", - Key: "", Data: nil, }, true, @@ -79,7 +77,6 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Description: "A new protocol for testing protocols", Protocol: "TestProtocol", Type: "TestType", - Key: "TestKey", Data: nil, }, true, @@ -90,8 +87,7 @@ func TestAddProtocolDataProposal_ValidateBasic(t *testing.T) { Title: "Valid Protocol Data", Description: "A valid protocol that is valid", Protocol: "ValidProtocol", - Type: "liquidtoken", - Key: "liquid", + Type: types.ProtocolDataType_name[int32(types.ProtocolDataTypeLiquidToken)], Data: []byte(validLiquidData), }, false, @@ -146,7 +142,6 @@ Data: { "ibcdenom": "ibc/3020922B7576FC75BBE057A0290A9AEEFF489BB1113E6E365CE472D4BFB7FFA3", "qassetdenom": "uqstake" } -Key: liquid ` t.Run("stringer", func(t *testing.T) { diff --git a/x/participationrewards/types/protocol_data.go b/x/participationrewards/types/protocol_data.go index b966f5111..dde9b8eff 100644 --- a/x/participationrewards/types/protocol_data.go +++ b/x/participationrewards/types/protocol_data.go @@ -67,6 +67,7 @@ func UnmarshalProtocolData(datatype ProtocolDataType, data json.RawMessage) (Pro type ProtocolDataI interface { ValidateBasic() error + GenerateKey() []byte } // ConnectionProtocolData defines state for connection tracking. @@ -100,6 +101,10 @@ func (cpd *ConnectionProtocolData) ValidateBasic() error { return nil } +func (cpd ConnectionProtocolData) GenerateKey() []byte { + return []byte(cpd.ChainID) +} + var ( _ ProtocolDataI = &ConnectionProtocolData{} _ ProtocolDataI = &OsmosisPoolProtocolData{} diff --git a/x/participationrewards/types/protocol_data_test.go b/x/participationrewards/types/protocol_data_test.go index fb7956187..f8004e6e3 100644 --- a/x/participationrewards/types/protocol_data_test.go +++ b/x/participationrewards/types/protocol_data_test.go @@ -197,12 +197,15 @@ func TestUnmarshalProtocolData(t *testing.T) { "osmosispool_data", args{ datatype: types.ProtocolDataTypeOsmosisPool, - data: []byte(`{"poolid": 1, "poolname": "atom/osmo","zones": {"cosmoshub-4": "IBC/atom_denom", "osmosis-1": "IBC/osmo_denom"}}`), + data: []byte(`{"poolid": 1, "poolname": "atom/osmo","denoms": {"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {"denom": "uatom", "chainid": "cosmoshub-4"}, "uosmo": {"denom": "uosmo", "chainid": "osmosis-1"}}}`), }, &types.OsmosisPoolProtocolData{ PoolID: 1, PoolName: "atom/osmo", - Zones: map[string]string{"cosmoshub-4": "IBC/atom_denom", "osmosis-1": "IBC/osmo_denom"}, + Denoms: map[string]types.DenomWithZone{ + "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {Denom: "uatom", ChainID: "cosmoshub-4"}, + "uosmo": {Denom: "uosmo", ChainID: "osmosis-1"}, + }, }, false, }, diff --git a/x/participationrewards/types/submodule_liquid.go b/x/participationrewards/types/submodule_liquid.go index b215a2e49..e78bc45a9 100644 --- a/x/participationrewards/types/submodule_liquid.go +++ b/x/participationrewards/types/submodule_liquid.go @@ -48,3 +48,7 @@ func (lpd *LiquidAllowedDenomProtocolData) ValidateBasic() error { return nil } + +func (lpd *LiquidAllowedDenomProtocolData) GenerateKey() []byte { + return []byte(lpd.ChainID + "_" + lpd.IbcDenom) +} diff --git a/x/participationrewards/types/submodule_osmosis.go b/x/participationrewards/types/submodule_osmosis.go index e70982d62..64a5423c7 100644 --- a/x/participationrewards/types/submodule_osmosis.go +++ b/x/participationrewards/types/submodule_osmosis.go @@ -3,12 +3,15 @@ package types import ( "encoding/json" "fmt" + "strings" "time" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ingenuity-build/quicksilver/internal/multierror" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/balancer" "github.com/ingenuity-build/quicksilver/osmosis-types/gamm/pool-models/stableswap" + "github.com/ingenuity-build/quicksilver/utils" ) const ( @@ -19,12 +22,18 @@ const ( // OsmosisPoolProtocolData defines protocol state to track qAssets locked in // Osmosis pools. type OsmosisPoolProtocolData struct { - PoolID uint64 - PoolName string - LastUpdated time.Time - PoolData json.RawMessage - PoolType string - Zones map[string]string // chainID: IBC/denom + PoolID uint64 + PoolName string + LastUpdated time.Time + PoolData json.RawMessage + PoolType string + Denoms map[string]DenomWithZone + IsIncentivized bool +} + +type DenomWithZone struct { + Denom string + ChainID string } func (opd *OsmosisPoolProtocolData) GetPool() (gamm.PoolI, error) { @@ -81,15 +90,15 @@ func (opd *OsmosisPoolProtocolData) ValidateBasic() error { } i := 0 - for chainID, denom := range opd.Zones { - el := fmt.Sprintf("Zones[%d]", i) + for _, ibcdenom := range utils.Keys(opd.Denoms) { + el := fmt.Sprintf("Denoms[%s]", ibcdenom) - if chainID == "" { - errs[el+" key"] = fmt.Errorf("%w, chainID", ErrUndefinedAttribute) + if opd.Denoms[ibcdenom].ChainID == "" || len(strings.Split(opd.Denoms[ibcdenom].ChainID, "-")) < 2 { + errs[el+" key"] = fmt.Errorf("%w, chainID", ErrInvalidChainID) } - if denom == "" { - errs[el+" value"] = fmt.Errorf("%w, IBC/denom", ErrUndefinedAttribute) + if opd.Denoms[ibcdenom].Denom == "" || sdk.ValidateDenom(opd.Denoms[ibcdenom].Denom) != nil { + errs[el+" value"] = fmt.Errorf("%w, IBC/denom", ErrInvalidDenom) } i++ @@ -106,10 +115,16 @@ func (opd *OsmosisPoolProtocolData) ValidateBasic() error { return nil } +func (opd *OsmosisPoolProtocolData) GenerateKey() []byte { + return []byte(fmt.Sprintf("%d", opd.PoolID)) +} + // ----------------------------------------------------- type OsmosisParamsProtocolData struct { - ChainID string + ChainID string + BaseDenom string + BaseChain string } // ValidateBasic satisfies ProtocolDataI and validates basic stateless data. @@ -121,9 +136,21 @@ func (oppd *OsmosisParamsProtocolData) ValidateBasic() error { errs["ChainID"] = ErrUndefinedAttribute } + if oppd.BaseChain == "" { + errs["BaseChain"] = ErrUndefinedAttribute + } + + if oppd.BaseDenom == "" { + errs["BaseDenom"] = ErrUndefinedAttribute + } + if len(errs) > 0 { return multierror.New(errs) } return nil } + +func (oppd *OsmosisParamsProtocolData) GenerateKey() []byte { + return []byte("osmosisparams") +} diff --git a/x/participationrewards/types/submodule_osmosis_test.go b/x/participationrewards/types/submodule_osmosis_test.go index 12a991d81..473da02c8 100644 --- a/x/participationrewards/types/submodule_osmosis_test.go +++ b/x/participationrewards/types/submodule_osmosis_test.go @@ -10,7 +10,9 @@ import ( func TestOsmosisParamsProtocolData_ValidateBasic(t *testing.T) { type fields struct { - ChainID string + ChainID string + BaseChain string + BaseDenom string } tests := []struct { name string @@ -23,9 +25,18 @@ func TestOsmosisParamsProtocolData_ValidateBasic(t *testing.T) { true, }, { - "valid", + "missing-fields", fields{ - "test-01", + ChainID: "test-01", + }, + true, + }, + { + "value", + fields{ + ChainID: "test-01", + BaseDenom: "uosmo", + BaseChain: "test-01", }, false, }, @@ -33,7 +44,9 @@ func TestOsmosisParamsProtocolData_ValidateBasic(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { oppd := types.OsmosisParamsProtocolData{ - ChainID: tt.fields.ChainID, + ChainID: tt.fields.ChainID, + BaseDenom: tt.fields.BaseDenom, + BaseChain: tt.fields.BaseChain, } err := oppd.ValidateBasic() if tt.wantErr {