mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-10-13 16:49:18 +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: {}
|
||||
tags:
|
||||
- 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}:
|
||||
get:
|
||||
summary: Queries a list of GetMachineByPublicKey items.
|
||||
@ -75329,6 +75365,16 @@ definitions:
|
||||
description: params holds all the parameters of this module.
|
||||
type: object
|
||||
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:
|
||||
type: object
|
||||
properties:
|
||||
|
2
go.mod
2
go.mod
@ -5,6 +5,7 @@ go 1.19
|
||||
require (
|
||||
cosmossdk.io/api v0.3.1
|
||||
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/btcutil v1.1.2
|
||||
github.com/cometbft/cometbft v0.37.2
|
||||
@ -39,7 +40,6 @@ require (
|
||||
cosmossdk.io/core v0.5.1 // indirect
|
||||
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
|
||||
cosmossdk.io/log v1.1.0 // indirect
|
||||
cosmossdk.io/math v1.0.1 // indirect
|
||||
cosmossdk.io/tools/rosetta v0.2.1 // indirect
|
||||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
|
@ -9,6 +9,5 @@ import (
|
||||
|
||||
func TestE2ETestSuite(t *testing.T) {
|
||||
cfg := network.DefaultConfig()
|
||||
cfg.NumValidators = 1
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
||||
|
@ -5,17 +5,23 @@ import (
|
||||
"planetmint-go/testutil/network"
|
||||
"planetmint-go/testutil/sample"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
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"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
var (
|
||||
bobAddr sdk.AccAddress
|
||||
aliceAddr sdk.AccAddress
|
||||
)
|
||||
|
||||
// E2ETestSuite struct definition of dao suite
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
@ -33,7 +39,43 @@ func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
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
|
||||
@ -44,23 +86,45 @@ func (s *E2ETestSuite) TearDownSuite() {
|
||||
func (s *E2ETestSuite) TestDistributeCollectedFees() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
kb := val.ClientCtx.Keyring
|
||||
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
|
||||
// sending funds to alice
|
||||
args := []string{
|
||||
val.Moniker,
|
||||
addr.String(),
|
||||
sample.Amount,
|
||||
aliceAddr.String(),
|
||||
"1000stake",
|
||||
"--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)
|
||||
s.Require().NoError(err)
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, auth.GetAccountsCmd(), []string{})
|
||||
fmt.Println(out)
|
||||
s.network.WaitForNextBlock()
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
func Secp256k1AccAddress() sdk.AccAddress {
|
||||
pk := secp256k1.GenPrivKey().PubKey()
|
||||
addr := pk.Address()
|
||||
return sdk.AccAddress(addr)
|
||||
}
|
||||
|
||||
func Machine(name, pubKey string) machinetypes.Machine {
|
||||
metadata := Metadata()
|
||||
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
||||
|
@ -64,7 +64,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
|
||||
k.accountKeeper.IterateAccounts(ctx, func(acc authtypes.AccountI) bool {
|
||||
addr := acc.GetAddress()
|
||||
balance := k.bankKeeper.SpendableCoins(ctx, addr)
|
||||
found, stake := balance.Find("stake")
|
||||
found, stake := balance.Find("rddl")
|
||||
if found {
|
||||
totalStake = totalStake.Add(stake.Amount)
|
||||
balances[addr.String()] = stake.Amount
|
||||
@ -74,7 +74,8 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
|
||||
|
||||
distAddr := k.accountKeeper.GetModuleAddress(disttypes.ModuleName)
|
||||
distSpendableCoins := k.bankKeeper.SpendableCoins(ctx, distAddr)
|
||||
found, coinToDistribute := distSpendableCoins.Find("token")
|
||||
// found, coinToDistribute := distSpendableCoins.Find("stake")
|
||||
found, coinToDistribute := distSpendableCoins.Find("node0token")
|
||||
|
||||
if found {
|
||||
decTotalAmountToDistribute := sdk.NewDecFromInt(coinToDistribute.Amount)
|
||||
@ -85,7 +86,7 @@ func (k Keeper) DistributeCollectedFees(ctx sdk.Context) {
|
||||
claim := decTotalAmountToDistribute.Mul(share)
|
||||
if claim.GTE(sdk.OneDec()) {
|
||||
intClaim := claim.TruncateInt()
|
||||
coinClaim := sdk.NewCoin("token", intClaim)
|
||||
coinClaim := sdk.NewCoin("node0token", intClaim)
|
||||
accAddress, err := sdk.AccAddressFromBech32(addr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user