mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-04 05:06:39 +00:00
refactor asset rest test
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
5fb957b02f
commit
2874e577b0
@ -2,10 +2,13 @@ package asset
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"planetmint-go/testutil"
|
||||
"planetmint-go/testutil/sample"
|
||||
|
||||
assettypes "planetmint-go/x/asset/types"
|
||||
|
||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
)
|
||||
|
||||
func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
||||
@ -24,19 +27,60 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
||||
sk := hex.EncodeToString(privKey.Bytes())
|
||||
cidHash, signature := sample.Asset(sk)
|
||||
|
||||
msg := assettypes.MsgNotarizeAsset{
|
||||
Creator: addr.String(),
|
||||
Hash: cidHash,
|
||||
Signature: signature,
|
||||
PubKey: hex.EncodeToString(privKey.PubKey().Bytes()),
|
||||
testCases := []struct {
|
||||
name string
|
||||
msg assettypes.MsgNotarizeAsset
|
||||
rawLog string
|
||||
}{
|
||||
{
|
||||
"machine not found",
|
||||
assettypes.MsgNotarizeAsset{
|
||||
Creator: addr.String(),
|
||||
Hash: cidHash,
|
||||
Signature: signature,
|
||||
PubKey: "human pubkey",
|
||||
},
|
||||
"machine not found",
|
||||
},
|
||||
{
|
||||
"invalid signature",
|
||||
assettypes.MsgNotarizeAsset{
|
||||
Creator: addr.String(),
|
||||
Hash: cidHash,
|
||||
Signature: "invalid signature",
|
||||
PubKey: hex.EncodeToString(privKey.PubKey().Bytes()),
|
||||
},
|
||||
"invalid signature",
|
||||
},
|
||||
{
|
||||
"valid notarization",
|
||||
assettypes.MsgNotarizeAsset{
|
||||
Creator: addr.String(),
|
||||
Hash: cidHash,
|
||||
Signature: signature,
|
||||
PubKey: hex.EncodeToString(privKey.PubKey().Bytes()),
|
||||
},
|
||||
"planetmintgo.asset.MsgNotarizeAsset",
|
||||
},
|
||||
}
|
||||
|
||||
// Prepare Tx
|
||||
txBytes, err := testutil.PrepareTx(val, &msg, "machine")
|
||||
s.Require().NoError(err)
|
||||
for _, tc := range testCases {
|
||||
// Prepare Tx
|
||||
txBytes, err := testutil.PrepareTx(val, &tc.msg, "machine")
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Broadcast Tx
|
||||
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(uint32(0), broadcastTxResponse.TxResponse.Code)
|
||||
// Broadcast Tx
|
||||
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.network.WaitForNextBlock()
|
||||
|
||||
tx, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, broadcastTxResponse.TxResponse.TxHash))
|
||||
s.Require().NoError(err)
|
||||
|
||||
var txRes txtypes.GetTxResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(tx, &txRes)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Contains(txRes.TxResponse.RawLog, tc.rawLog)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user