Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into mbreithecker/cosmos-sdk-v0.50.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Jun 7, 2024
2 parents ba7661d + 6c33762 commit 0bbb6eb
Show file tree
Hide file tree
Showing 6 changed files with 349 additions and 179 deletions.
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKz
github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM=
github.com/Joker/jade v1.1.3 h1:Qbeh12Vq6BxURXT1qZBRHsDxeURB8ztcL6f3EXSGeHk=
github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM=
github.com/KYVENetwork/interchaintest/v8 v8.0.0-20240520124515-fd4cc797e6fd h1:lKJ7X9Q+KbQviDxpY4OaalC8/oZ64rXfTNTny4jfuE0=
github.com/KYVENetwork/interchaintest/v8 v8.0.0-20240520124515-fd4cc797e6fd/go.mod h1:pupV0YN3A56/u9kHj9U1F8MdDUEolBIn05F0W1q/0oI=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw=
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
Expand Down
204 changes: 204 additions & 0 deletions interchaintest/global/abci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
package global_test

import (
"context"
"testing"

"cosmossdk.io/math"
i "github.com/KYVENetwork/chain/testutil/integration"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
)

/*
TEST CASES - x/global/abci.go
* BurnRatio = 0.0
* BurnRatio = 2/3 - test truncate
* BurnRatio = 0.5
* BurnRatio = 1.0
*/

func TestProposalHandler(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "interchaintest/x/global Test Suite")
}

var _ = Describe("x/global/abci.go - Endblocker", func() {
It("BurnRatio = 0.0", func() {
// ARRANGE
ctx := context.Background()
burnRatio := math.LegacyZeroDec()

chain, interchain, broadcaster, wallet := startNewChainWithCustomBurnRatio(ctx, burnRatio)
DeferCleanup(func() {
_ = chain.StopAllNodes(context.Background())
_ = interchain.Close()
})

balanceBefore, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())
result, err := chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupplyBefore := result.AmountOf(chain.Config().Denom)

// ACT
msgSend := &banktypes.MsgSend{
FromAddress: wallet.FormattedAddress(),
ToAddress: wallet.FormattedAddress(),
Amount: sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, math.NewInt(i.T_KYVE))),
}
tx, err := cosmos.BroadcastTx(ctx, broadcaster, wallet, msgSend)

// ASSERT
Expect(err).To(BeNil())
Expect(tx.Code).To(Equal(uint32(0)))

balance, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())

accountBalanceDifference := balanceBefore.Sub(balance)
Expect(accountBalanceDifference.Int64()).To(Equal(int64(200_000)))

result, err = chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupply := result.AmountOf(chain.Config().Denom)
Expect(totalSupply).To(Equal(totalSupplyBefore))
})

It("BurnRatio = 2/3 - test truncate", func() {
// ARRANGE
ctx := context.Background()
burnRatio := math.LegacyOneDec().MulInt64(2).QuoInt64(3)

chain, interchain, broadcaster, wallet := startNewChainWithCustomBurnRatio(ctx, burnRatio)
DeferCleanup(func() {
_ = chain.StopAllNodes(context.Background())
_ = interchain.Close()
})

balanceBefore, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())
result, err := chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupplyBefore := result.AmountOf(chain.Config().Denom)

// ACT
msgSend := &banktypes.MsgSend{
FromAddress: wallet.FormattedAddress(),
ToAddress: wallet.FormattedAddress(),
Amount: sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, math.NewInt(i.T_KYVE))),
}
tx, err := cosmos.BroadcastTx(ctx, broadcaster, wallet, msgSend)

// ASSERT
Expect(err).To(BeNil())
Expect(tx.Code).To(Equal(uint32(0)))

balance, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())

accountBalanceDifference := balanceBefore.Sub(balance)
Expect(accountBalanceDifference.Int64()).To(Equal(int64(200_000)))

result, err = chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupply := result.AmountOf(chain.Config().Denom)
totalSupplyDifference := totalSupplyBefore.Sub(totalSupply)

// Expect ..666 not ..667
Expect(totalSupplyDifference).To(Equal(math.NewInt(133_333)))
})

It("BurnRatio = 0.5", func() {
// ARRANGE
ctx := context.Background()
burnRatio := math.LegacyMustNewDecFromStr("0.5")

chain, interchain, broadcaster, wallet := startNewChainWithCustomBurnRatio(ctx, burnRatio)
DeferCleanup(func() {
_ = chain.StopAllNodes(context.Background())
_ = interchain.Close()
})

balanceBefore, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())
result, err := chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupplyBefore := result.AmountOf(chain.Config().Denom)

// ACT
msgSend := &banktypes.MsgSend{
FromAddress: wallet.FormattedAddress(),
ToAddress: wallet.FormattedAddress(),
Amount: sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, math.NewInt(i.T_KYVE))),
}
tx, err := cosmos.BroadcastTx(ctx, broadcaster, wallet, msgSend)

// ASSERT
Expect(err).To(BeNil())
Expect(tx.Code).To(Equal(uint32(0)))

balance, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())

accountBalanceDifference := balanceBefore.Sub(balance)
Expect(accountBalanceDifference.Int64()).To(Equal(int64(200_000)))

result, err = chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupply := result.AmountOf(chain.Config().Denom)
totalSupplyDifference := totalSupplyBefore.Sub(totalSupply)

Expect(totalSupplyDifference).To(Equal(math.NewInt(100_000)))
})

It("BurnRatio = 1.0", func() {
// ARRANGE
ctx := context.Background()
burnRatio := math.LegacyMustNewDecFromStr("1.0")

chain, interchain, broadcaster, wallet := startNewChainWithCustomBurnRatio(ctx, burnRatio)
DeferCleanup(func() {
_ = chain.StopAllNodes(context.Background())
_ = interchain.Close()
})

balanceBefore, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())
result, err := chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupplyBefore := result.AmountOf(chain.Config().Denom)

// ACT
msgSend := &banktypes.MsgSend{
FromAddress: wallet.FormattedAddress(),
ToAddress: wallet.FormattedAddress(),
Amount: sdk.NewCoins(sdk.NewCoin(chain.Config().Denom, math.NewInt(i.T_KYVE))),
}
tx, err := cosmos.BroadcastTx(ctx, broadcaster, wallet, msgSend)

// ASSERT
Expect(err).To(BeNil())
Expect(tx.Code).To(Equal(uint32(0)))

balance, err := chain.GetBalance(ctx, wallet.FormattedAddress(), chain.Config().Denom)
Expect(err).To(BeNil())

accountBalanceDifference := balanceBefore.Sub(balance)
Expect(accountBalanceDifference.Int64()).To(Equal(int64(200_000)))

result, err = chain.BankQueryTotalSupply(ctx)
Expect(err).To(BeNil())
totalSupply := result.AmountOf(chain.Config().Denom)
totalSupplyDifference := totalSupplyBefore.Sub(totalSupply)

Expect(totalSupplyDifference).To(Equal(math.NewInt(200_000)))
})
})
135 changes: 135 additions & 0 deletions interchaintest/global/abci_utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package global_test

import (
"context"
"encoding/json"
"strconv"

"cosmossdk.io/math"

"github.com/KYVENetwork/chain/app"
i "github.com/KYVENetwork/chain/testutil/integration"
sdk "github.com/cosmos/cosmos-sdk/types"
sdktestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/icza/dyno"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"go.uber.org/zap/zaptest"
)

const (
uidGid = "1025:1025"
)

func encodingConfig() *sdktestutil.TestEncodingConfig {
cfg := sdktestutil.TestEncodingConfig{}
a := app.Setup()

cfg.Codec = a.AppCodec()
cfg.TxConfig = authtx.NewTxConfig(a.AppCodec(), authtx.DefaultSignModes)
cfg.InterfaceRegistry = a.InterfaceRegistry()
cfg.Amino = a.LegacyAmino()

return &cfg
}

func mainnetChainSpec(numValidators int, numFullNodes int, burnRatio math.LegacyDec) *interchaintest.ChainSpec {
return &interchaintest.ChainSpec{
NumValidators: &numValidators,
NumFullNodes: &numFullNodes,
ChainConfig: ibc.ChainConfig{
Type: "cosmos",
Name: "kyve",
ChainID: "kyve-1",
Bin: "kyved",
Bech32Prefix: "kyve",
Denom: "ukyve",
GasPrices: "1ukyve",
GasAdjustment: 10,
TrustingPeriod: "112h",
NoHostMount: false,
EncodingConfig: encodingConfig(),
ModifyGenesis: modifyGenesis(burnRatio),
Images: []ibc.DockerImage{{
Repository: "kyve",
Version: "local",
UidGid: uidGid,
}},
},
}
}

func modifyGenesis(burnRatio math.LegacyDec) func(config ibc.ChainConfig, genbz []byte) ([]byte, error) {
return func(config ibc.ChainConfig, genbz []byte) ([]byte, error) {
genesis := make(map[string]interface{})
_ = json.Unmarshal(genbz, &genesis)

teamSupply := math.NewInt(165_000_000_000_000)
balances, _ := dyno.GetSlice(genesis, "app_state", "bank", "balances")
balances = append(balances, bankTypes.Balance{
Address: "kyve1e29j95xmsw3zmvtrk4st8e89z5n72v7nf70ma4",
Coins: sdk.NewCoins(sdk.NewCoin(config.Denom, teamSupply)),
})
_ = dyno.Set(genesis, balances, "app_state", "bank", "balances")
totalSupply, _ := dyno.GetSlice(genesis, "app_state", "bank", "supply")

// Update total supply
coin := totalSupply[0].(map[string]interface{})
amountStr := coin["amount"].(string)
amount, _ := strconv.Atoi(amountStr)
totalSupply[0] = sdk.NewCoin(config.Denom, math.NewInt(int64(amount)+teamSupply.Int64()))
_ = dyno.Set(genesis, totalSupply, "app_state", "bank", "supply")

// Set burn ratio to given value
_ = dyno.Set(genesis, burnRatio,
"app_state", "global", "params", "burn_ratio",
)

// Set inflation to zero
_ = dyno.Set(genesis, math.LegacyZeroDec(),
"app_state", "mint", "params", "inflation_min",
)
_ = dyno.Set(genesis, math.LegacyZeroDec(),
"app_state", "mint", "params", "inflation_max",
)

newGenesis, _ := json.Marshal(genesis)
return newGenesis, nil
}
}

// startNewChainWithCustomBurnRatio starts a new chain with the given burn ratio and an inflation of zero.
func startNewChainWithCustomBurnRatio(ctx context.Context, burnRatio math.LegacyDec) (*cosmos.CosmosChain, *interchaintest.Interchain, *cosmos.Broadcaster, *cosmos.CosmosWallet) {
numFullNodes := 0
numValidators := 2
factory := interchaintest.NewBuiltinChainFactory(
zaptest.NewLogger(GinkgoT()),
[]*interchaintest.ChainSpec{mainnetChainSpec(numValidators, numFullNodes, burnRatio)},
)

chains, err := factory.Chains(GinkgoT().Name())
Expect(err).To(BeNil())
chain := chains[0].(*cosmos.CosmosChain)

interchain := interchaintest.NewInterchain().AddChain(chain)

broadcaster := cosmos.NewBroadcaster(GinkgoT(), chain)

dockerClient, network := interchaintest.DockerSetup(GinkgoT())

err = interchain.Build(ctx, nil, interchaintest.InterchainBuildOptions{
TestName: GinkgoT().Name(),
Client: dockerClient,
NetworkID: network,
SkipPathCreation: true,
})
Expect(err).To(BeNil())

wallet := interchaintest.GetAndFundTestUsers(GinkgoT(), ctx, GinkgoT().Name(), math.NewInt(10*i.T_KYVE), chain)[0].(*cosmos.CosmosWallet)
return chain, interchain, broadcaster, wallet
}
7 changes: 4 additions & 3 deletions interchaintest/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package relayer_test

import (
"context"
"testing"

"cosmossdk.io/math"
"github.com/KYVENetwork/chain/testutil/integration"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testreporter"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
"testing"

"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos"
"go.uber.org/zap/zaptest"
Expand Down Expand Up @@ -98,8 +99,8 @@ var _ = Describe("ibc", Ordered, func() {
It("Transfer 1 $KYVE to Osmosis and back", func() {
// ARRANGE
startBalance := math.NewInt(10 * integration.T_KYVE)
var kyveWallet = interchaintest.GetAndFundTestUsers(GinkgoT(), ctx, GinkgoT().Name(), startBalance, kyve)[0].(*cosmos.CosmosWallet)
var osmosisWallet = interchaintest.GetAndFundTestUsers(GinkgoT(), ctx, GinkgoT().Name(), startBalance, osmosis)[0].(*cosmos.CosmosWallet)
kyveWallet := interchaintest.GetAndFundTestUsers(GinkgoT(), ctx, GinkgoT().Name(), startBalance, kyve)[0].(*cosmos.CosmosWallet)
osmosisWallet := interchaintest.GetAndFundTestUsers(GinkgoT(), ctx, GinkgoT().Name(), startBalance, osmosis)[0].(*cosmos.CosmosWallet)

kyveChans, err := rel.GetChannels(ctx, eRep, kyve.Config().ChainID)
Expect(err).To(BeNil())
Expand Down
6 changes: 4 additions & 2 deletions interchaintest/ibc/ibc_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package relayer_test

import (
"cosmossdk.io/math"
"encoding/json"
"strconv"

"cosmossdk.io/math"

"github.com/KYVENetwork/chain/app"
sdk "github.com/cosmos/cosmos-sdk/types"
sdktestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
Expand All @@ -13,7 +16,6 @@ import (
"github.com/onsi/gomega/types"
"github.com/strangelove-ventures/interchaintest/v8"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"strconv"
)

const (
Expand Down
Loading

0 comments on commit 0bbb6eb

Please sign in to comment.