mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-10-14 00:59:21 +00:00
implement e2e test scenario for fee distribution
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
f9de021deb
commit
05a484c8b9
46
docs/static/openapi.yml
vendored
46
docs/static/openapi.yml
vendored
@ -46473,6 +46473,42 @@ paths:
|
|||||||
additionalProperties: {}
|
additionalProperties: {}
|
||||||
tags:
|
tags:
|
||||||
- Query
|
- Query
|
||||||
|
/planetmint-go/dao/params:
|
||||||
|
get:
|
||||||
|
summary: Parameters queries the parameters of the module.
|
||||||
|
operationId: PlanetmintgoDaoParams
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: A successful response.
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
params:
|
||||||
|
description: params holds all the parameters of this module.
|
||||||
|
type: object
|
||||||
|
description: >-
|
||||||
|
QueryParamsResponse is response type for the Query/Params RPC
|
||||||
|
method.
|
||||||
|
default:
|
||||||
|
description: An unexpected error response.
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
details:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
'@type':
|
||||||
|
type: string
|
||||||
|
additionalProperties: {}
|
||||||
|
tags:
|
||||||
|
- Query
|
||||||
/planetmint-go/machine/get_machine_by_public_key/{publicKey}:
|
/planetmint-go/machine/get_machine_by_public_key/{publicKey}:
|
||||||
get:
|
get:
|
||||||
summary: Queries a list of GetMachineByPublicKey items.
|
summary: Queries a list of GetMachineByPublicKey items.
|
||||||
@ -75329,6 +75365,16 @@ definitions:
|
|||||||
description: params holds all the parameters of this module.
|
description: params holds all the parameters of this module.
|
||||||
type: object
|
type: object
|
||||||
description: QueryParamsResponse is response type for the Query/Params RPC method.
|
description: QueryParamsResponse is response type for the Query/Params RPC method.
|
||||||
|
planetmintgo.dao.Params:
|
||||||
|
type: object
|
||||||
|
description: Params defines the parameters for the module.
|
||||||
|
planetmintgo.dao.QueryParamsResponse:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
params:
|
||||||
|
description: params holds all the parameters of this module.
|
||||||
|
type: object
|
||||||
|
description: QueryParamsResponse is response type for the Query/Params RPC method.
|
||||||
planetmintgo.machine.Machine:
|
planetmintgo.machine.Machine:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
2
go.mod
2
go.mod
@ -5,6 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
cosmossdk.io/api v0.3.1
|
cosmossdk.io/api v0.3.1
|
||||||
cosmossdk.io/errors v1.0.0-beta.7
|
cosmossdk.io/errors v1.0.0-beta.7
|
||||||
|
cosmossdk.io/math v1.0.1
|
||||||
github.com/btcsuite/btcd v0.23.0
|
github.com/btcsuite/btcd v0.23.0
|
||||||
github.com/btcsuite/btcd/btcutil v1.1.2
|
github.com/btcsuite/btcd/btcutil v1.1.2
|
||||||
github.com/cometbft/cometbft v0.37.2
|
github.com/cometbft/cometbft v0.37.2
|
||||||
@ -39,7 +40,6 @@ require (
|
|||||||
cosmossdk.io/core v0.5.1 // indirect
|
cosmossdk.io/core v0.5.1 // indirect
|
||||||
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
|
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
|
||||||
cosmossdk.io/log v1.1.0 // indirect
|
cosmossdk.io/log v1.1.0 // indirect
|
||||||
cosmossdk.io/math v1.0.1 // indirect
|
|
||||||
cosmossdk.io/tools/rosetta v0.2.1 // indirect
|
cosmossdk.io/tools/rosetta v0.2.1 // indirect
|
||||||
filippo.io/edwards25519 v1.0.0 // indirect
|
filippo.io/edwards25519 v1.0.0 // indirect
|
||||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||||
|
@ -9,6 +9,5 @@ import (
|
|||||||
|
|
||||||
func TestE2ETestSuite(t *testing.T) {
|
func TestE2ETestSuite(t *testing.T) {
|
||||||
cfg := network.DefaultConfig()
|
cfg := network.DefaultConfig()
|
||||||
cfg.NumValidators = 1
|
|
||||||
suite.Run(t, NewE2ETestSuite(cfg))
|
suite.Run(t, NewE2ETestSuite(cfg))
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,23 @@ import (
|
|||||||
"planetmint-go/testutil/network"
|
"planetmint-go/testutil/network"
|
||||||
"planetmint-go/testutil/sample"
|
"planetmint-go/testutil/sample"
|
||||||
|
|
||||||
|
"cosmossdk.io/math"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
||||||
|
|
||||||
clitestutil "planetmint-go/testutil/cli"
|
clitestutil "planetmint-go/testutil/cli"
|
||||||
|
|
||||||
auth "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
bobAddr sdk.AccAddress
|
||||||
|
aliceAddr sdk.AccAddress
|
||||||
|
)
|
||||||
|
|
||||||
// E2ETestSuite struct definition of dao suite
|
// E2ETestSuite struct definition of dao suite
|
||||||
type E2ETestSuite struct {
|
type E2ETestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
@ -33,7 +39,43 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
|||||||
func (s *E2ETestSuite) SetupSuite() {
|
func (s *E2ETestSuite) SetupSuite() {
|
||||||
s.T().Log("setting up e2e test suite")
|
s.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
s.network = network.New(s.T())
|
// set accounts for alice and bob in genesis state
|
||||||
|
var authGenState authtypes.GenesisState
|
||||||
|
s.cfg.Codec.MustUnmarshalJSON(s.cfg.GenesisState[authtypes.ModuleName], &authGenState)
|
||||||
|
|
||||||
|
bobAddr = sample.Secp256k1AccAddress()
|
||||||
|
aliceAddr = sample.Secp256k1AccAddress()
|
||||||
|
|
||||||
|
bob := authtypes.NewBaseAccount(bobAddr, nil, 0, 0)
|
||||||
|
alice := authtypes.NewBaseAccount(aliceAddr, nil, 0, 0)
|
||||||
|
|
||||||
|
accounts, err := authtypes.PackAccounts(authtypes.GenesisAccounts{bob, alice})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
authGenState.Accounts = append(authGenState.Accounts, accounts...)
|
||||||
|
s.cfg.GenesisState[authtypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&authGenState)
|
||||||
|
|
||||||
|
// set the balances in the genesis state
|
||||||
|
var bankGenState banktypes.GenesisState
|
||||||
|
s.cfg.Codec.MustUnmarshalJSON(s.cfg.GenesisState[banktypes.ModuleName], &bankGenState)
|
||||||
|
|
||||||
|
bbalances := sdk.NewCoins(
|
||||||
|
sdk.NewCoin("rddl", math.NewInt(10000)),
|
||||||
|
)
|
||||||
|
|
||||||
|
abalances := sdk.NewCoins(
|
||||||
|
sdk.NewCoin("rddl", math.NewInt(5000)),
|
||||||
|
)
|
||||||
|
|
||||||
|
accountBalances := []banktypes.Balance{
|
||||||
|
{Address: bobAddr.String(), Coins: bbalances.Sort()},
|
||||||
|
{Address: aliceAddr.String(), Coins: abalances.Sort()},
|
||||||
|
}
|
||||||
|
bankGenState.Balances = append(bankGenState.Balances, accountBalances...)
|
||||||
|
s.cfg.GenesisState[banktypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&bankGenState)
|
||||||
|
|
||||||
|
s.cfg.MinGasPrices = fmt.Sprintf("0.000006%s", "node0token")
|
||||||
|
s.network = network.New(s.T(), s.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TearDownSuite clean up after testing
|
// TearDownSuite clean up after testing
|
||||||
@ -44,23 +86,45 @@ func (s *E2ETestSuite) TearDownSuite() {
|
|||||||
func (s *E2ETestSuite) TestDistributeCollectedFees() {
|
func (s *E2ETestSuite) TestDistributeCollectedFees() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
kb := val.ClientCtx.Keyring
|
// sending funds to alice
|
||||||
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sample.DefaultDerivationPath, hd.Secp256k1)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
addr, _ := account.GetAddress()
|
|
||||||
|
|
||||||
// sending funds to machine to initialize account on chain
|
|
||||||
args := []string{
|
args := []string{
|
||||||
val.Moniker,
|
val.Moniker,
|
||||||
addr.String(),
|
aliceAddr.String(),
|
||||||
sample.Amount,
|
"1000stake",
|
||||||
"--yes",
|
"--yes",
|
||||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
|
// fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
|
||||||
|
fmt.Sprintf("--%s=%s", flags.FlagFees, "10node0token"),
|
||||||
}
|
}
|
||||||
|
_, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.network.WaitForNextBlock()
|
||||||
|
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||||
|
aliceAddr.String(),
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.T().Log(out)
|
||||||
|
|
||||||
|
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||||
|
bobAddr.String(),
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.T().Log(out)
|
||||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, auth.GetAccountsCmd(), []string{})
|
s.network.WaitForNextBlock()
|
||||||
fmt.Println(out)
|
|
||||||
|
s.network.WaitForNextBlock()
|
||||||
|
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||||
|
aliceAddr.String(),
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.T().Log(out)
|
||||||
|
|
||||||
|
out, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||||
|
bobAddr.String(),
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.T().Log(out)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,12 @@ func AccAddress() string {
|
|||||||
return sdk.AccAddress(addr).String()
|
return sdk.AccAddress(addr).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Secp256k1AccAddress() sdk.AccAddress {
|
||||||
|
pk := secp256k1.GenPrivKey().PubKey()
|
||||||
|
addr := pk.Address()
|
||||||
|
return sdk.AccAddress(addr)
|
||||||
|
}
|
||||||
|
|
||||||
func Machine(name, pubKey string) machinetypes.Machine {
|
func Machine(name, pubKey string) machinetypes.Machine {
|
||||||
metadata := Metadata()
|
metadata := Metadata()
|
||||||
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
||||||
|
@ -64,7 +64,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
|
|||||||
k.accountKeeper.IterateAccounts(ctx, func(acc authtypes.AccountI) bool {
|
k.accountKeeper.IterateAccounts(ctx, func(acc authtypes.AccountI) bool {
|
||||||
addr := acc.GetAddress()
|
addr := acc.GetAddress()
|
||||||
balance := k.bankKeeper.SpendableCoins(ctx, addr)
|
balance := k.bankKeeper.SpendableCoins(ctx, addr)
|
||||||
found, stake := balance.Find("stake")
|
found, stake := balance.Find("rddl")
|
||||||
if found {
|
if found {
|
||||||
totalStake = totalStake.Add(stake.Amount)
|
totalStake = totalStake.Add(stake.Amount)
|
||||||
balances[addr.String()] = stake.Amount
|
balances[addr.String()] = stake.Amount
|
||||||
@ -74,7 +74,8 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
|
|||||||
|
|
||||||
distAddr := k.accountKeeper.GetModuleAddress(disttypes.ModuleName)
|
distAddr := k.accountKeeper.GetModuleAddress(disttypes.ModuleName)
|
||||||
distSpendableCoins := k.bankKeeper.SpendableCoins(ctx, distAddr)
|
distSpendableCoins := k.bankKeeper.SpendableCoins(ctx, distAddr)
|
||||||
found, coinToDistribute := distSpendableCoins.Find("token")
|
// found, coinToDistribute := distSpendableCoins.Find("stake")
|
||||||
|
found, coinToDistribute := distSpendableCoins.Find("node0token")
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
decTotalAmountToDistribute := sdk.NewDecFromInt(coinToDistribute.Amount)
|
decTotalAmountToDistribute := sdk.NewDecFromInt(coinToDistribute.Amount)
|
||||||
@ -85,7 +86,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
|
|||||||
claim := decTotalAmountToDistribute.Mul(share)
|
claim := decTotalAmountToDistribute.Mul(share)
|
||||||
if claim.GTE(sdk.OneDec()) {
|
if claim.GTE(sdk.OneDec()) {
|
||||||
intClaim := claim.TruncateInt()
|
intClaim := claim.TruncateInt()
|
||||||
coinClaim := sdk.NewCoin("token", intClaim)
|
coinClaim := sdk.NewCoin("node0token", intClaim)
|
||||||
accAddress, err := sdk.AccAddressFromBech32(addr)
|
accAddress, err := sdk.AccAddressFromBech32(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user