mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-06 14:16:39 +00:00
test: refactor broadcast tx into function (#259)
Force test cases to check tx response for errors. * refactor: improve broadcast error logging Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
parent
fa05ec7fff
commit
3e23260a9c
@ -79,7 +79,7 @@ func (s *E2ETestSuite) TestNotarizeAsset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
out, err := lib.BroadcastTxWithFileLock(addr, tc.msg)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), addr, tc.msg)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
txResponse, err := lib.GetTxResponseFromOut(out)
|
txResponse, err := lib.GetTxResponseFromOut(out)
|
||||||
|
@ -123,13 +123,13 @@ func (s *E2ETestSuite) TestDistributeCollectedFees() {
|
|||||||
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
|
coin := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
|
||||||
msg := banktypes.NewMsgSend(val.Address, aliceAddr, coin)
|
msg := banktypes.NewMsgSend(val.Address, aliceAddr, coin)
|
||||||
|
|
||||||
_, err := lib.BroadcastTxWithFileLock(val.Address, msg)
|
_, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = s.network.WaitForNextBlock()
|
err = s.network.WaitForNextBlock()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, msg)
|
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
err = s.network.WaitForNextBlock()
|
err = s.network.WaitForNextBlock()
|
||||||
@ -158,13 +158,9 @@ func (s *E2ETestSuite) TestMintToken() {
|
|||||||
|
|
||||||
mintRequest := sample.MintRequest(aliceAddr.String(), 1000, "hash")
|
mintRequest := sample.MintRequest(aliceAddr.String(), 1000, "hash")
|
||||||
msg1 := daotypes.NewMsgMintToken(val.Address.String(), &mintRequest)
|
msg1 := daotypes.NewMsgMintToken(val.Address.String(), &mintRequest)
|
||||||
out, err := lib.BroadcastTxWithFileLock(val.Address, msg1)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
txResponse, err := lib.GetTxResponseFromOut(out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
s.Require().Equal(int(0), int(txResponse.Code))
|
|
||||||
|
|
||||||
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)
|
||||||
@ -195,7 +191,7 @@ func (s *E2ETestSuite) TestMintToken() {
|
|||||||
out, err = lib.BroadcastTxWithFileLock(addr, msg1)
|
out, err = lib.BroadcastTxWithFileLock(addr, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
txResponse, err = lib.GetTxResponseFromOut(out)
|
txResponse, err := lib.GetTxResponseFromOut(out)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(int(2), int(txResponse.Code))
|
s.Require().Equal(int(2), int(txResponse.Code))
|
||||||
}
|
}
|
||||||
@ -275,7 +271,7 @@ func (s *E2ETestSuite) TestPoPResult() {
|
|||||||
challenges[i].Finished = true
|
challenges[i].Finished = true
|
||||||
|
|
||||||
msg := daotypes.NewMsgReportPopResult(val.Address.String(), &challenges[i])
|
msg := daotypes.NewMsgReportPopResult(val.Address.String(), &challenges[i])
|
||||||
out, err := lib.BroadcastTxWithFileLock(val.Address, msg)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
@ -312,7 +308,7 @@ func (s *E2ETestSuite) TestPoPResult() {
|
|||||||
msg1 := daotypes.NewMsgReissueRDDLProposal(val.Address.String(), hex.EncodeToString(val.PubKey.Address()),
|
msg1 := daotypes.NewMsgReissueRDDLProposal(val.Address.String(), hex.EncodeToString(val.PubKey.Address()),
|
||||||
"reissueasset 7add40beb27df701e02ee85089c5bc0021bc813823fedb5f1dcb5debda7f3da9 2996.57534244",
|
"reissueasset 7add40beb27df701e02ee85089c5bc0021bc813823fedb5f1dcb5debda7f3da9 2996.57534244",
|
||||||
challenges[4].Height, challenges[0].Height, challenges[2].Height)
|
challenges[4].Height, challenges[0].Height, challenges[2].Height)
|
||||||
output, err := lib.BroadcastTxWithFileLock(val.Address, msg1)
|
output, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
@ -322,7 +318,7 @@ func (s *E2ETestSuite) TestPoPResult() {
|
|||||||
|
|
||||||
// send ReissuanceResult
|
// send ReissuanceResult
|
||||||
msg2 := daotypes.NewMsgReissueRDDLResult(val.Address.String(), aliceAddr.String(), "TxID", challenges[4].Height)
|
msg2 := daotypes.NewMsgReissueRDDLResult(val.Address.String(), aliceAddr.String(), "TxID", challenges[4].Height)
|
||||||
output, err = lib.BroadcastTxWithFileLock(val.Address, msg2)
|
output, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg2)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
@ -340,7 +336,7 @@ func (s *E2ETestSuite) TestPoPResult() {
|
|||||||
InvestorTxID: "InvestorTxID",
|
InvestorTxID: "InvestorTxID",
|
||||||
}
|
}
|
||||||
msg3 := daotypes.NewMsgDistributionRequest(val.Address.String(), &distributionOrder)
|
msg3 := daotypes.NewMsgDistributionRequest(val.Address.String(), &distributionOrder)
|
||||||
output, err = lib.BroadcastTxWithFileLock(val.Address, msg3)
|
output, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg3)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
@ -350,7 +346,7 @@ func (s *E2ETestSuite) TestPoPResult() {
|
|||||||
|
|
||||||
// send DistributionResult
|
// send DistributionResult
|
||||||
msg4 := daotypes.NewMsgDistributionResult(val.Address.String(), challenges[2].Height, "DaoTxID", "InvestorTxID", "PoPTxID")
|
msg4 := daotypes.NewMsgDistributionResult(val.Address.String(), challenges[2].Height, "DaoTxID", "InvestorTxID", "PoPTxID")
|
||||||
output, err = lib.BroadcastTxWithFileLock(val.Address, msg4)
|
output, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg4)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
|||||||
|
|
||||||
ta := sample.TrustAnchor(pubKey)
|
ta := sample.TrustAnchor(pubKey)
|
||||||
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
out, err := lib.BroadcastTxWithFileLock(val.Address, msg1)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
@ -82,7 +82,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
|||||||
|
|
||||||
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||||
msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
out, err = lib.BroadcastTxWithFileLock(addr, msg2)
|
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
@ -156,13 +156,8 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
|||||||
|
|
||||||
ta := sample.TrustAnchor(pubKey)
|
ta := sample.TrustAnchor(pubKey)
|
||||||
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
out, err := lib.BroadcastTxWithFileLock(val.Address, msg1)
|
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
_, err = clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
// create allowance for machine
|
// create allowance for machine
|
||||||
@ -178,13 +173,8 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
|||||||
|
|
||||||
msg2, err := feegrant.NewMsgGrantAllowance(grant, val.Address, addr)
|
msg2, err := feegrant.NewMsgGrantAllowance(grant, val.Address, addr)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, msg2)
|
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg2)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
_, err = clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
// attest machine with fee granter without funding the machine account first
|
// attest machine with fee granter without funding the machine account first
|
||||||
@ -199,13 +189,8 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
|||||||
libConfig.SetClientCtx(clientCtx)
|
libConfig.SetClientCtx(clientCtx)
|
||||||
|
|
||||||
msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
_, err = lib.BroadcastTxWithFileLock(addr, msg3)
|
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg3)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
|
||||||
_, err = clitestutil.GetRawLogFromTxOut(val, out)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
|
29
testutil/e2e/tx.go
Normal file
29
testutil/e2e/tx.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BuildSignBroadcastTx builds, signs and broadcasts transaction to the network.
|
||||||
|
func BuildSignBroadcastTx(t *testing.T, addr sdk.AccAddress, msg sdk.Msg) (out *bytes.Buffer, err error) {
|
||||||
|
out, err = lib.BroadcastTxWithFileLock(addr, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Log("broadcast tx failed: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
txResponse, err := lib.GetTxResponseFromOut(out)
|
||||||
|
if err != nil {
|
||||||
|
t.Log("getting tx response from out failed: " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if txResponse.Code != 0 {
|
||||||
|
err = errors.New(txResponse.RawLog)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -33,12 +33,16 @@ func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingV
|
|||||||
GetAppLogger().Error(ctx, loggingContext+" getting tx response from out failed: "+err.Error())
|
GetAppLogger().Error(ctx, loggingContext+" getting tx response from out failed: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if txResponse.Code == 0 {
|
||||||
|
GetAppLogger().Info(ctx, loggingContext+" broadcast tx succeeded")
|
||||||
|
return
|
||||||
|
}
|
||||||
txResponseJSON, err := yaml.YAMLToJSON([]byte(txResponse.String()))
|
txResponseJSON, err := yaml.YAMLToJSON([]byte(txResponse.String()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
GetAppLogger().Error(ctx, loggingContext+" converting tx response from yaml to json failed: "+err.Error())
|
GetAppLogger().Error(ctx, loggingContext+" converting tx response from yaml to json failed: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
GetAppLogger().Info(ctx, loggingContext+" broadcast tx succeeded: "+string(txResponseJSON))
|
GetAppLogger().Error(ctx, loggingContext+" broadcast tx failed: "+string(txResponseJSON))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user