From f7253024d287e55c83ab1f54cf18f4bb036f0a03 Mon Sep 17 00:00:00 2001 From: Lorenz Herzberger Date: Tue, 12 Sep 2023 17:00:20 +0200 Subject: [PATCH] fix asset e2e test suite for extended keypair Signed-off-by: Lorenz Herzberger --- tests/e2e/asset/rest.go | 13 ++++++++++--- tests/e2e/asset/suite.go | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/e2e/asset/rest.go b/tests/e2e/asset/rest.go index 97f3ffd..77757f2 100644 --- a/tests/e2e/asset/rest.go +++ b/tests/e2e/asset/rest.go @@ -1,10 +1,13 @@ package asset import ( + "encoding/hex" "fmt" "planetmint-go/testutil" "planetmint-go/testutil/sample" + "github.com/btcsuite/btcd/btcutil/hdkeychain" + assettypes "planetmint-go/x/asset/types" txtypes "github.com/cosmos/cosmos-sdk/types/tx" @@ -21,7 +24,11 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() { addr, err := k.GetAddress() s.Require().NoError(err) - cidHash, signature := sample.Asset(prvKey) + xskKey, _ := hdkeychain.NewKeyFromString(xPrvKey) + privKey, _ := xskKey.ECPrivKey() + byte_key := privKey.Serialize() + sk := hex.EncodeToString(byte_key) + cidHash, signature := sample.Asset(sk) testCases := []struct { name string @@ -44,7 +51,7 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() { Creator: addr.String(), Hash: cidHash, Signature: "invalid signature", - PubKey: pubKey, + PubKey: xPubKey, }, "invalid signature", }, @@ -54,7 +61,7 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() { Creator: addr.String(), Hash: cidHash, Signature: signature, - PubKey: pubKey, + PubKey: xPubKey, }, "planetmintgo.asset.MsgNotarizeAsset", }, diff --git a/tests/e2e/asset/suite.go b/tests/e2e/asset/suite.go index 1f51b09..b426d68 100644 --- a/tests/e2e/asset/suite.go +++ b/tests/e2e/asset/suite.go @@ -1,8 +1,10 @@ package asset import ( + "encoding/hex" "encoding/json" "fmt" + "planetmint-go/config" "planetmint-go/testutil/network" "planetmint-go/testutil/sample" @@ -10,6 +12,7 @@ import ( assetcli "planetmint-go/x/asset/client/cli" machinecli "planetmint-go/x/machine/client/cli" + "github.com/btcsuite/btcd/btcutil/hdkeychain" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -19,8 +22,10 @@ import ( ) var ( - pubKey string - prvKey string + pubKey string + prvKey string + xPubKey string + xPrvKey string ) // E2ETestSuite struct definition of asset suite @@ -72,6 +77,7 @@ func (s *E2ETestSuite) SetupSuite() { s.Require().NoError(s.network.WaitForNextBlock()) prvKey, pubKey = sample.KeyPair() + xPrvKey, xPubKey = sample.ExtendedKeyPair(config.PlmntNetParams) ta := sample.TrustAnchor(pubKey) taJSON, err := json.Marshal(&ta) @@ -121,7 +127,11 @@ func (s *E2ETestSuite) TearDownSuite() { func (s *E2ETestSuite) TestNotarizeAsset() { val := s.network.Validators[0] - cidHash, signature := sample.Asset(prvKey) + xskKey, _ := hdkeychain.NewKeyFromString(xPrvKey) + privKey, _ := xskKey.ECPrivKey() + byte_key := privKey.Serialize() + sk := hex.EncodeToString(byte_key) + cidHash, signature := sample.Asset(sk) testCases := []struct { name string @@ -145,7 +155,7 @@ func (s *E2ETestSuite) TestNotarizeAsset() { []string{ "cid", "signature", - pubKey, + xPubKey, fmt.Sprintf("--%s=%s", flags.FlagFrom, sample.Name), fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees), "--yes", @@ -157,7 +167,7 @@ func (s *E2ETestSuite) TestNotarizeAsset() { []string{ cidHash, signature, - pubKey, + xPubKey, fmt.Sprintf("--%s=%s", flags.FlagFrom, sample.Name), fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees), "--yes",