-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refs/heads/main' into mbreithecker/cosmos-sdk-v0.50.7
- Loading branch information
Showing
6 changed files
with
349 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.