test: add balance check to machine attestation e2e test

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2024-04-18 10:22:17 +02:00
parent 63649c868c
commit 7c6e30d4d1
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A

View File

@ -1,6 +1,8 @@
package machine
import (
"bytes"
"github.com/planetmint/planetmint-go/lib"
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
"github.com/planetmint/planetmint-go/testutil/network"
@ -12,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
txcli "github.com/cosmos/cosmos-sdk/x/auth/tx"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
"github.com/cosmos/cosmos-sdk/x/feegrant"
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
"github.com/stretchr/testify/assert"
@ -75,6 +78,17 @@ func (s *E2ETestSuite) TestAttestMachine() {
s.Require().NoError(err)
addr, _ := k.GetAddress()
// Check preAttestationBalance in order to verify that it doesn't change after machine attestation
preAttestationBalanceOutput, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
addr.String(),
})
s.Require().NoError(err)
preAttestationBalance, ok := preAttestationBalanceOutput.(*bytes.Buffer)
if !ok {
err = lib.ErrTypeAssertionFailed
s.Require().NoError(err)
}
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
@ -104,6 +118,19 @@ func (s *E2ETestSuite) TestAttestMachine() {
assert.Contains(s.T(), txResp.TxHash, txResponse.TxHash)
s.Require().NoError(err)
// Check postAttestationBalance as it should be the same as prior to the machine attestation
postAttestationBalanceOutput, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
addr.String(),
})
s.Require().NoError(err)
postAttestationBalance, ok := postAttestationBalanceOutput.(*bytes.Buffer)
if !ok {
err = lib.ErrTypeAssertionFailed
s.Require().NoError(err)
}
assert.Equal(s.T(), preAttestationBalance, postAttestationBalance)
}
func (s *E2ETestSuite) TestInvalidAttestMachine() {