mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-06 14:16: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 (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"planetmint-go/testutil"
|
"planetmint-go/testutil"
|
||||||
"planetmint-go/testutil/sample"
|
"planetmint-go/testutil/sample"
|
||||||
|
|
||||||
assettypes "planetmint-go/x/asset/types"
|
assettypes "planetmint-go/x/asset/types"
|
||||||
|
|
||||||
|
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
||||||
@ -24,19 +27,60 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
|||||||
sk := hex.EncodeToString(privKey.Bytes())
|
sk := hex.EncodeToString(privKey.Bytes())
|
||||||
cidHash, signature := sample.Asset(sk)
|
cidHash, signature := sample.Asset(sk)
|
||||||
|
|
||||||
msg := assettypes.MsgNotarizeAsset{
|
testCases := []struct {
|
||||||
Creator: addr.String(),
|
name string
|
||||||
Hash: cidHash,
|
msg assettypes.MsgNotarizeAsset
|
||||||
Signature: signature,
|
rawLog string
|
||||||
PubKey: hex.EncodeToString(privKey.PubKey().Bytes()),
|
}{
|
||||||
|
{
|
||||||
|
"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
|
for _, tc := range testCases {
|
||||||
txBytes, err := testutil.PrepareTx(val, &msg, "machine")
|
// Prepare Tx
|
||||||
s.Require().NoError(err)
|
txBytes, err := testutil.PrepareTx(val, &tc.msg, "machine")
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Broadcast Tx
|
// Broadcast Tx
|
||||||
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Equal(uint32(0), broadcastTxResponse.TxResponse.Code)
|
|
||||||
|
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