Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: hardcode legacy amino endpoint e2e test data #15397

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 37 additions & 36 deletions tests/e2e/tx/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"fmt"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -901,13 +902,19 @@ func (s *E2ETestSuite) TestTxDecode_GRPCGateway() {
}
}

func (s *E2ETestSuite) TestTxEncodeAmino_GRPC() {
func (s *E2ETestSuite) readTestAminoTxJSON() ([]byte, *legacytx.StdTx) {
val := s.network.Validators[0]
txBuilder := s.mkTxBuilder()
stdTx, err := clienttx.ConvertTxToStdTx(val.ClientCtx.LegacyAmino, txBuilder.GetTx())
txJSONBytes, err := os.ReadFile("testdata/tx_amino1.json")
s.Require().NoError(err)
txJSONBytes, err := val.ClientCtx.LegacyAmino.MarshalJSON(stdTx)
var stdTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.UnmarshalJSON(txJSONBytes, &stdTx)
s.Require().NoError(err)
return txJSONBytes, &stdTx
}

func (s *E2ETestSuite) TestTxEncodeAmino_GRPC() {
val := s.network.Validators[0]
txJSONBytes, stdTx := s.readTestAminoTxJSON()

testCases := []struct {
name string
Expand All @@ -933,22 +940,18 @@ func (s *E2ETestSuite) TestTxEncodeAmino_GRPC() {
s.Require().NoError(err)
s.Require().NotEmpty(res.GetAminoBinary())

var tx legacytx.StdTx
stdTxConfig := legacytx.StdTxConfig{Cdc: val.ClientCtx.LegacyAmino}
stdTxConfig.Cdc.Unmarshal(res.AminoBinary, &tx)
s.Require().Equal(tx.GetMsgs(), stdTx.GetMsgs())
var decodedTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.Unmarshal(res.AminoBinary, &decodedTx)
s.Require().NoError(err)
s.Require().Equal(decodedTx.GetMsgs(), stdTx.GetMsgs())
}
})
}
}

func (s *E2ETestSuite) TestTxEncodeAmino_GRPCGateway() {
val := s.network.Validators[0]
txBuilder := s.mkTxBuilder()
stdTx, err := clienttx.ConvertTxToStdTx(val.ClientCtx.LegacyAmino, txBuilder.GetTx())
s.Require().NoError(err)
txJSONBytes, err := val.ClientCtx.LegacyAmino.MarshalJSON(stdTx)
s.Require().NoError(err)
txJSONBytes, stdTx := s.readTestAminoTxJSON()

testCases := []struct {
name string
Expand All @@ -975,24 +978,27 @@ func (s *E2ETestSuite) TestTxEncodeAmino_GRPCGateway() {
err := val.ClientCtx.Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)

var newStdTx legacytx.StdTx
stdTxConfig := legacytx.StdTxConfig{Cdc: val.ClientCtx.LegacyAmino}
stdTxConfig.Cdc.Unmarshal(result.AminoBinary, &newStdTx)
s.Require().Equal(newStdTx.GetMsgs(), stdTx.GetMsgs())
var decodedTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.Unmarshal(result.AminoBinary, &decodedTx)
s.Require().NoError(err)
s.Require().Equal(decodedTx.GetMsgs(), stdTx.GetMsgs())
}
})
}
}

func (s *E2ETestSuite) TestTxDecodeAmino_GRPC() {
func (s *E2ETestSuite) readTestAminoTxBinary() ([]byte, *legacytx.StdTx) {
val := s.network.Validators[0]
txBuilder := s.mkTxBuilder()

stdTx, err := clienttx.ConvertTxToStdTx(val.ClientCtx.LegacyAmino, txBuilder.GetTx())
txJSONBytes, err := os.ReadFile("testdata/tx_amino1.bin")
s.Require().NoError(err)
stdTxConfig := legacytx.StdTxConfig{Cdc: val.ClientCtx.LegacyAmino}
encodedTx, err := stdTxConfig.Cdc.Marshal(stdTx)
var stdTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.Unmarshal(txJSONBytes, &stdTx)
s.Require().NoError(err)
return txJSONBytes, &stdTx
}

func (s *E2ETestSuite) TestTxDecodeAmino_GRPC() {
encodedTx, stdTx := s.readTestAminoTxBinary()

invalidTxBytes := append(encodedTx, byte(0o00))

Expand Down Expand Up @@ -1020,24 +1026,18 @@ func (s *E2ETestSuite) TestTxDecodeAmino_GRPC() {
s.Require().NoError(err)
s.Require().NotEmpty(res.GetAminoJson())

var tx legacytx.StdTx
err := stdTxConfig.Cdc.UnmarshalJSON([]byte(res.GetAminoJson()), &tx)
var decodedTx legacytx.StdTx
err = s.network.Validators[0].ClientCtx.LegacyAmino.UnmarshalJSON([]byte(res.GetAminoJson()), &decodedTx)
s.Require().NoError(err)
s.Require().Equal(stdTx.GetMsgs(), tx.GetMsgs())
s.Require().Equal(stdTx.GetMsgs(), decodedTx.GetMsgs())
}
})
}
}

func (s *E2ETestSuite) TestTxDecodeAmino_GRPCGateway() {
val := s.network.Validators[0]
txBuilder := s.mkTxBuilder()

stdTx, err := clienttx.ConvertTxToStdTx(val.ClientCtx.LegacyAmino, txBuilder.GetTx())
s.Require().NoError(err)
stdTxConfig := legacytx.StdTxConfig{Cdc: val.ClientCtx.LegacyAmino}
encodedTx, err := stdTxConfig.Cdc.Marshal(stdTx)
s.Require().NoError(err)
encodedTx, stdTx := s.readTestAminoTxBinary()

invalidTxBytes := append(encodedTx, byte(0o00))

Expand Down Expand Up @@ -1066,9 +1066,10 @@ func (s *E2ETestSuite) TestTxDecodeAmino_GRPCGateway() {
err := val.ClientCtx.Codec.UnmarshalJSON(res, &result)
s.Require().NoError(err)

var newStdTx legacytx.StdTx
stdTxConfig.Cdc.UnmarshalJSON([]byte(result.AminoJson), &newStdTx)
s.Require().Equal(newStdTx.GetMsgs(), stdTx.GetMsgs())
var decodedTx legacytx.StdTx
err = val.ClientCtx.LegacyAmino.UnmarshalJSON([]byte(result.AminoJson), &decodedTx)
s.Require().NoError(err)
s.Require().Equal(stdTx.GetMsgs(), decodedTx.GetMsgs())
}
})
}
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/tx/testdata/tx_amino1.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
((�
o��a�
-cosmos1hzw8v2kk4csg8xr3fhy8ykyymykknm2tdgvf7k-cosmos1hzw8v2kk4csg8xr3fhy8ykyymykknm2tdgvf7k
stake10

stake10�� "foobar
1 change: 1 addition & 0 deletions tests/e2e/tx/testdata/tx_amino1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgSend","value":{"from_address":"cosmos1hzw8v2kk4csg8xr3fhy8ykyymykknm2tdgvf7k","to_address":"cosmos1hzw8v2kk4csg8xr3fhy8ykyymykknm2tdgvf7k","amount":[{"denom":"stake","amount":"10"}]}}],"fee":{"amount":[{"denom":"stake","amount":"10"}],"gas":"200000"},"signatures":[],"memo":"foobar","timeout_height":"0"}}