mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-07 22:56:37 +00:00
Use lib in rest e2e machine test (#263)
* refactor: align variable name with rest of the code Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
parent
ae161f11e5
commit
6d05f85cbd
@ -42,8 +42,8 @@ func NewPopSelectionE2ETestSuite(cfg network.Config) *PopSelectionE2ETestSuite {
|
|||||||
|
|
||||||
func (s *PopSelectionE2ETestSuite) SetupSuite() {
|
func (s *PopSelectionE2ETestSuite) SetupSuite() {
|
||||||
s.T().Log("setting up e2e test suite")
|
s.T().Log("setting up e2e test suite")
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
cfg.FeeDenom = "stake"
|
conf.FeeDenom = "stake"
|
||||||
|
|
||||||
s.network = network.New(s.T(), s.cfg)
|
s.network = network.New(s.T(), s.cfg)
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ func (s *PopSelectionE2ETestSuite) TestPopSelection() {
|
|||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
// set PopEpochs to 1 in Order to trigger some participant selections
|
// set PopEpochs to 1 in Order to trigger some participant selections
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
cfg.PopEpochs = 1
|
conf.PopEpochs = 1
|
||||||
|
|
||||||
// wait for some blocks so challenges get stored
|
// wait for some blocks so challenges get stored
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
@ -8,13 +8,14 @@ import (
|
|||||||
"github.com/planetmint/planetmint-go/testutil/network"
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
|
|
||||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RestE2ETestSuite struct definition of machine suite
|
||||||
type RestE2ETestSuite struct {
|
type RestE2ETestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
@ -22,13 +23,15 @@ type RestE2ETestSuite struct {
|
|||||||
network *network.Network
|
network *network.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewRestE2ETestSuite returns configured machine RestE2ETestSuite
|
||||||
func NewRestE2ETestSuite(cfg network.Config) *RestE2ETestSuite {
|
func NewRestE2ETestSuite(cfg network.Config) *RestE2ETestSuite {
|
||||||
return &RestE2ETestSuite{cfg: cfg}
|
return &RestE2ETestSuite{cfg: cfg}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetupSuite initializes machine E2ETestSuite
|
||||||
func (s *RestE2ETestSuite) SetupSuite() {
|
func (s *RestE2ETestSuite) SetupSuite() {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
cfg.FeeDenom = "stake"
|
conf.FeeDenom = "stake"
|
||||||
|
|
||||||
s.T().Log("setting up e2e test suite")
|
s.T().Log("setting up e2e test suite")
|
||||||
|
|
||||||
@ -64,13 +67,14 @@ func (s *RestE2ETestSuite) TestAttestMachineREST() {
|
|||||||
Creator: addr.String(),
|
Creator: addr.String(),
|
||||||
TrustAnchor: &ta,
|
TrustAnchor: &ta,
|
||||||
}
|
}
|
||||||
txBytes, err := testutil.PrepareTx(val, &taMsg, sample.Name)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), addr, &taMsg)
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
_, err = testutil.BroadcastTx(val, txBytes)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgRegisterTrustAnchor")
|
||||||
|
|
||||||
// Create Attest Machine TX
|
// Create Attest Machine TX
|
||||||
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||||
@ -78,21 +82,18 @@ func (s *RestE2ETestSuite) TestAttestMachineREST() {
|
|||||||
Creator: addr.String(),
|
Creator: addr.String(),
|
||||||
Machine: &machine,
|
Machine: &machine,
|
||||||
}
|
}
|
||||||
|
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, &msg)
|
||||||
txBytes, err = testutil.PrepareTx(val, &msg, sample.Name)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// give machine attestation some time to issue the liquid asset
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
tx, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, broadcastTxResponse.TxResponse.TxHash))
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
|
rawLog, err = clitestutil.GetRawLogFromTxOut(val, out)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
var txRes txtypes.GetTxResponse
|
assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgAttestMachine")
|
||||||
err = val.ClientCtx.Codec.UnmarshalJSON(tx, &txRes)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Equal(uint32(0), txRes.TxResponse.Code)
|
|
||||||
|
|
||||||
queryMachineURL := fmt.Sprintf("%s/planetmint/machine/get_machine_by_public_key/%s", baseURL, pubKey)
|
queryMachineURL := fmt.Sprintf("%s/planetmint/machine/get_machine_by_public_key/%s", baseURL, pubKey)
|
||||||
queryMachineRes, err := testutil.GetRequest(queryMachineURL)
|
queryMachineRes, err := testutil.GetRequest(queryMachineURL)
|
||||||
|
@ -78,7 +78,11 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
|||||||
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// give machine attestation some time to issue the liquid asset
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
rawLog, err = clitestutil.GetRawLogFromTxOut(val, out)
|
rawLog, err = clitestutil.GetRawLogFromTxOut(val, out)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
@ -172,6 +176,10 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
|||||||
msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg3)
|
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg3)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// give machine attestation some time to issue the liquid asset
|
||||||
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
// reset clientCtx to validator ctx
|
// reset clientCtx to validator ctx
|
||||||
|
@ -55,12 +55,12 @@ func New(t *testing.T, configs ...Config) *Network {
|
|||||||
appLogger.SetTestingLogger(t)
|
appLogger.SetTestingLogger(t)
|
||||||
|
|
||||||
// set the proper root dir for the test environment so that the abci.go logic works
|
// set the proper root dir for the test environment so that the abci.go logic works
|
||||||
appConfig := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
appConfig.SetRoot(validatorTmpDir + "/node0/simd")
|
conf.SetRoot(validatorTmpDir + "/node0/simd")
|
||||||
|
|
||||||
net, err := network.New(t, validatorTmpDir, cfg)
|
net, err := network.New(t, validatorTmpDir, cfg)
|
||||||
|
|
||||||
appConfig.ValidatorAddress = net.Validators[0].Address.String()
|
conf.ValidatorAddress = net.Validators[0].Address.String()
|
||||||
// set missing validator client context values for sending txs
|
// set missing validator client context values for sending txs
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
net.Validators[0].ClientCtx.BroadcastMode = "sync"
|
net.Validators[0].ClientCtx.BroadcastMode = "sync"
|
||||||
@ -72,7 +72,7 @@ func New(t *testing.T, configs ...Config) *Network {
|
|||||||
|
|
||||||
libConfig := lib.GetConfig()
|
libConfig := lib.GetConfig()
|
||||||
libConfig.SetClientCtx(net.Validators[0].ClientCtx)
|
libConfig.SetClientCtx(net.Validators[0].ClientCtx)
|
||||||
libConfig.SetFeeDenom(appConfig.FeeDenom)
|
libConfig.SetFeeDenom(conf.FeeDenom)
|
||||||
libConfig.SetRoot(validatorTmpDir + "/node0/simd")
|
libConfig.SetRoot(validatorTmpDir + "/node0/simd")
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -54,18 +54,18 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isPopHeight(height int64) bool {
|
func isPopHeight(height int64) bool {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
return height%int64(cfg.PopEpochs) == 0
|
return height%int64(conf.PopEpochs) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func isReIssuanceHeight(height int64) bool {
|
func isReIssuanceHeight(height int64) bool {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
return height%int64(cfg.ReIssuanceEpochs) == 0
|
return height%int64(conf.ReIssuanceEpochs) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func isDistributionHeight(height int64) bool {
|
func isDistributionHeight(height int64) bool {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
return height%int64(cfg.DistributionEpochs) == 0
|
return height%int64(conf.DistributionEpochs) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock, k keeper.Keeper) {
|
func EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock, k keeper.Keeper) {
|
||||||
|
@ -153,10 +153,10 @@ func (k Keeper) processBalances(ctx sdk.Context, balances map[string]math.Int, t
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) SelectPopParticipants(ctx sdk.Context) (challenger string, challengee string) {
|
func (k Keeper) SelectPopParticipants(ctx sdk.Context) (challenger string, challengee string) {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
|
|
||||||
var startAccountNumber uint64
|
var startAccountNumber uint64
|
||||||
lastPopHeight := ctx.BlockHeight() - int64(cfg.PopEpochs)
|
lastPopHeight := ctx.BlockHeight() - int64(conf.PopEpochs)
|
||||||
lastPop, found := k.LookupChallenge(ctx, lastPopHeight)
|
lastPop, found := k.LookupChallenge(ctx, lastPopHeight)
|
||||||
if lastPopHeight > 0 && found {
|
if lastPopHeight > 0 && found {
|
||||||
lastAccountAddr := sdk.MustAccAddressFromBech32(lastPop.Challengee)
|
lastAccountAddr := sdk.MustAccAddressFromBech32(lastPop.Challengee)
|
||||||
|
@ -64,17 +64,17 @@ func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64)
|
|||||||
|
|
||||||
// convert per account
|
// convert per account
|
||||||
func (k msgServer) convertClaim(ctx sdk.Context, participant string, amount uint64) (err error) {
|
func (k msgServer) convertClaim(ctx sdk.Context, participant string, amount uint64) (err error) {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
accAddr, err := sdk.AccAddressFromBech32(participant)
|
accAddr, err := sdk.AccAddressFromBech32(participant)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
accStagedClaim := k.bankKeeper.GetBalance(ctx, accAddr, cfg.StagedDenom)
|
accStagedClaim := k.bankKeeper.GetBalance(ctx, accAddr, conf.StagedDenom)
|
||||||
|
|
||||||
if accStagedClaim.Amount.GTE(sdk.NewIntFromUint64(amount)) {
|
if accStagedClaim.Amount.GTE(sdk.NewIntFromUint64(amount)) {
|
||||||
burnCoins := sdk.NewCoins(sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(amount)))
|
burnCoins := sdk.NewCoins(sdk.NewCoin(conf.StagedDenom, sdk.NewIntFromUint64(amount)))
|
||||||
mintCoins := sdk.NewCoins(sdk.NewCoin(cfg.ClaimDenom, sdk.NewIntFromUint64(amount)))
|
mintCoins := sdk.NewCoins(sdk.NewCoin(conf.ClaimDenom, sdk.NewIntFromUint64(amount)))
|
||||||
|
|
||||||
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, accAddr, types.ModuleName, burnCoins)
|
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, accAddr, types.ModuleName, burnCoins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func (k msgServer) MintToken(goCtx context.Context, msg *types.MsgMintToken) (*types.MsgMintTokenResponse, error) {
|
func (k msgServer) MintToken(goCtx context.Context, msg *types.MsgMintToken) (*types.MsgMintTokenResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
|
|
||||||
_, found := k.GetMintRequestByHash(ctx, msg.GetMintRequest().GetLiquidTxHash())
|
_, found := k.GetMintRequestByHash(ctx, msg.GetMintRequest().GetLiquidTxHash())
|
||||||
if found {
|
if found {
|
||||||
@ -25,7 +25,7 @@ func (k msgServer) MintToken(goCtx context.Context, msg *types.MsgMintToken) (*t
|
|||||||
return nil, errorsmod.Wrapf(types.ErrInvalidAddress, "for provided address %s", beneficiary)
|
return nil, errorsmod.Wrapf(types.ErrInvalidAddress, "for provided address %s", beneficiary)
|
||||||
}
|
}
|
||||||
|
|
||||||
coin := sdk.NewCoin(cfg.TokenDenom, sdk.NewIntFromUint64(amt))
|
coin := sdk.NewCoin(conf.TokenDenom, sdk.NewIntFromUint64(amt))
|
||||||
coins := sdk.NewCoins(coin)
|
coins := sdk.NewCoins(coin)
|
||||||
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, coins)
|
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -32,10 +32,10 @@ func (k msgServer) ReportPopResult(goCtx context.Context, msg *types.MsgReportPo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (err error) {
|
func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (err error) {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
total, _, _ := util.GetPopReward(challenge.Height)
|
total, _, _ := util.GetPopReward(challenge.Height)
|
||||||
|
|
||||||
stagedCRDDL := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(total))
|
stagedCRDDL := sdk.NewCoin(conf.StagedDenom, sdk.NewIntFromUint64(total))
|
||||||
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL))
|
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(stagedCRDDL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -57,11 +57,11 @@ func (k msgServer) issuePoPRewards(ctx sdk.Context, challenge types.Challenge) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (k msgServer) handlePoPSuccess(ctx sdk.Context, challenge types.Challenge) (err error) {
|
func (k msgServer) handlePoPSuccess(ctx sdk.Context, challenge types.Challenge) (err error) {
|
||||||
cfg := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
_, challengerAmt, challengeeAmt := util.GetPopReward(challenge.Height)
|
_, challengerAmt, challengeeAmt := util.GetPopReward(challenge.Height)
|
||||||
|
|
||||||
challengerCoin := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(challengerAmt))
|
challengerCoin := sdk.NewCoin(conf.StagedDenom, sdk.NewIntFromUint64(challengerAmt))
|
||||||
challengeeCoin := sdk.NewCoin(cfg.StagedDenom, sdk.NewIntFromUint64(challengeeAmt))
|
challengeeCoin := sdk.NewCoin(conf.StagedDenom, sdk.NewIntFromUint64(challengeeAmt))
|
||||||
challengee, err := sdk.AccAddressFromBech32(challenge.Challengee)
|
challengee, err := sdk.AccAddressFromBech32(challenge.Challengee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user