mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-06 22:26:43 +00:00
implement TestAttestMachineREST
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
24511388d2
commit
c1389ea931
@ -9,9 +9,7 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||||
@ -110,72 +108,25 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
|
|||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
}
|
}
|
||||||
|
|
||||||
marshalledReq, err := val.ClientCtx.Codec.MarshalJSON(&req)
|
broadCastTxBody, err := val.ClientCtx.Codec.MarshalJSON(&req)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
r, err := testutil.PostRequest(broadcastTxUrl, "application/json", marshalledReq)
|
broadCastTxResponse, err := testutil.PostRequest(broadcastTxUrl, "application/json", broadCastTxBody)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.T().Log("RESULT:")
|
var bctRes txtypes.BroadcastTxResponse
|
||||||
s.T().Log(string(r))
|
err = val.ClientCtx.Codec.UnmarshalJSON(broadCastTxResponse, &bctRes)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(uint32(0), bctRes.TxResponse.Code)
|
||||||
|
|
||||||
s.T().Log(string(pubKey))
|
|
||||||
urlPubKey := url.QueryEscape(pubKey)
|
urlPubKey := url.QueryEscape(pubKey)
|
||||||
s.T().Log(string(urlPubKey))
|
|
||||||
|
|
||||||
queryMachineUrl := fmt.Sprintf("%s/planetmint-go/machine/get_machine_by_public_key/%s", baseURL, urlPubKey)
|
queryMachineUrl := fmt.Sprintf("%s/planetmint-go/machine/get_machine_by_public_key/%s", baseURL, urlPubKey)
|
||||||
s.T().Log(string(queryMachineUrl))
|
|
||||||
queryMachineRes, err := testutil.GetRequest(queryMachineUrl)
|
queryMachineRes, err := testutil.GetRequest(queryMachineUrl)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.T().Log(string(queryMachineRes))
|
|
||||||
|
|
||||||
// Encode TX
|
var qmRes machinetypes.QueryGetMachineByPublicKeyResponse
|
||||||
reqEncodeTx := fmt.Sprintf("%s/cosmos/tx/v1beta1/encode", baseURL)
|
err = val.ClientCtx.Codec.UnmarshalJSON(queryMachineRes, &qmRes)
|
||||||
|
|
||||||
msgs := make([]*types.Any, 1)
|
|
||||||
msgs[0], err = cdctypes.NewAnyWithValue(&msg)
|
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(&machine, qmRes.Machine)
|
||||||
signerInfos := make([]*txtypes.SignerInfo, 1)
|
|
||||||
signerInfos[0] = &txtypes.SignerInfo{}
|
|
||||||
signerInfos[0].PublicKey = &types.Any{
|
|
||||||
TypeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
|
||||||
Value: k.PubKey.Value,
|
|
||||||
}
|
|
||||||
signerInfos[0].ModeInfo = &txtypes.ModeInfo{
|
|
||||||
Sum: &txtypes.ModeInfo_Single_{
|
|
||||||
Single: &txtypes.ModeInfo_Single{
|
|
||||||
Mode: signing.SignMode_SIGN_MODE_DIRECT,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
signerInfos[0].Sequence = resAccountInfo.Info.Sequence
|
|
||||||
|
|
||||||
reqEncodeTxBody := txtypes.TxEncodeRequest{
|
|
||||||
Tx: &txtypes.Tx{
|
|
||||||
Body: &txtypes.TxBody{
|
|
||||||
Messages: msgs,
|
|
||||||
Memo: "",
|
|
||||||
TimeoutHeight: 0,
|
|
||||||
ExtensionOptions: []*types.Any{},
|
|
||||||
NonCriticalExtensionOptions: []*types.Any{},
|
|
||||||
},
|
|
||||||
AuthInfo: &txtypes.AuthInfo{
|
|
||||||
SignerInfos: signerInfos,
|
|
||||||
Tip: nil,
|
|
||||||
},
|
|
||||||
Signatures: [][]byte{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
reqEncodeTxBodyBytes, err := reqEncodeTxBody.Marshal()
|
|
||||||
s.Require().NoError(err)
|
|
||||||
// var resEncodeTX TXEncodeRequest
|
|
||||||
respEncodeTx, err := testutil.PostRequest(reqEncodeTx, "application/json", reqEncodeTxBodyBytes)
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
s.T().Log(string(respEncodeTx))
|
|
||||||
// Send encoded TX to /cosmos/tx/v1beta1/txs
|
|
||||||
|
|
||||||
// Query Machine by Pubkey
|
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Queryable pubkey for TestAttestMachine
|
// Queryable pubkey for TestAttestMachine
|
||||||
// const pubKey = "A/ZrbETECRq5DNGJZ0aH0DjlV4Y1opMlRfGoEJH454eB"
|
|
||||||
// const mnemonic = "science humor project sword foil amazing exhibit afford kangaroo child pulse adapt camera trigger isolate pull approve october dragon critic vendor panic business valve"
|
|
||||||
const pubKey = "AjKN6HiWucu1EBwzX0ACnkvomJiLRwq79oPxoLMY1zRw"
|
const pubKey = "AjKN6HiWucu1EBwzX0ACnkvomJiLRwq79oPxoLMY1zRw"
|
||||||
const mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
|
const mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user