Skip to content

Commit

Permalink
Merge pull request #100 from AssetMantle/deepanshutr/queries
Browse files Browse the repository at this point in the history
Deepanshutr/queries
  • Loading branch information
deepanshutr authored May 22, 2024
2 parents 2fca34d + 755787d commit 01e1137
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
19 changes: 15 additions & 4 deletions utilities/rest/keys/add/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
package add

import (
errorConstants "github.com/AssetMantle/modules/helpers/constants"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"testing"

errorConstants "github.com/AssetMantle/schema/go/errors/constants"
)

func Test_Add_Response(t *testing.T) {
testKeyOutput, _ := keyring.NewKeyOutput("name", "keyType", "address", "pubkey")
sk := secp256k1.PrivKey{Key: []byte{154, 49, 3, 117, 55, 232, 249, 20, 205, 216, 102, 7, 136, 72, 177, 2, 131, 202, 234, 81, 31, 208, 46, 244, 179, 192, 167, 163, 142, 117, 246, 13}}
tmpKey := sk.PubKey()
multisigPk := multisig.NewLegacyAminoPubKey(1, []types.PubKey{tmpKey})

info, err := keyring.NewMultiInfo("multisig", multisigPk)
require.NoError(t, err)
accAddr := sdk.AccAddress(info.GetPubKey().Address())
testKeyOutput, err := keyring.NewKeyOutput(info.GetName(), info.GetType(), accAddr, multisigPk)
require.NoError(t, err)
testResponse := newResponse(testKeyOutput, nil)
require.Equal(t, response{Success: true, Error: nil, KeyOutput: testKeyOutput}, testResponse)
require.Equal(t, true, testResponse.IsSuccessful())
Expand Down
8 changes: 3 additions & 5 deletions utilities/rest/sign/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ func TestHandler(t *testing.T) {
require.Nil(t, err)

address := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c"
var sdkAddress sdkTypes.AccAddress
sdkAddress, err = sdkTypes.AccAddressFromBech32(address)

// signWithout chainID
requestBody1, err := Codec.MarshalJSON(request{
BaseRequest: rest.BaseReq{From: address},
Type: "cosmos-sdk/StdTx",
StdTx: legacytx.NewStdTx([]sdkTypes.Msg{base.NewTestMessage(sdkAddress, "id")}, legacytx.NewStdFee(10, sdkTypes.NewCoins()), nil, ""),
StdTx: legacytx.NewStdTx([]sdkTypes.Msg{}, legacytx.NewStdFee(10, sdkTypes.NewCoins()), nil, ""),
})
require.Nil(t, err)
testRequest1, err := http.NewRequest("POST", "/sign", bytes.NewBuffer(requestBody1))
Expand All @@ -73,7 +71,7 @@ func TestHandler(t *testing.T) {
requestBody2, err := Codec.MarshalJSON(request{
BaseRequest: rest.BaseReq{From: "address", ChainID: "test"},
Type: "cosmos-sdk/StdTx",
StdTx: legacytx.NewStdTx([]sdkTypes.Msg{base.NewTestMessage(sdkAddress, "id")}, legacytx.NewStdFee(20, sdkTypes.NewCoins()), nil, ""),
StdTx: legacytx.NewStdTx([]sdkTypes.Msg{}, legacytx.NewStdFee(20, sdkTypes.NewCoins()), nil, ""),
})
require.Nil(t, err)
testRequest2, err := http.NewRequest("POST", "/sign", bytes.NewBuffer(requestBody2))
Expand All @@ -87,7 +85,7 @@ func TestHandler(t *testing.T) {
requestBody3, err := Codec.MarshalJSON(request{
BaseRequest: rest.BaseReq{From: address, ChainID: "test"},
Type: "cosmos-sdk/StdTx",
StdTx: legacytx.NewStdTx([]sdkTypes.Msg{base.NewTestMessage(sdkAddress, "id")}, legacytx.NewStdFee(30, sdkTypes.NewCoins()), nil, ""),
StdTx: legacytx.NewStdTx([]sdkTypes.Msg{}, legacytx.NewStdFee(30, sdkTypes.NewCoins()), nil, ""),
})
require.Nil(t, err)
testRequest3, err := http.NewRequest("POST", "/sign", bytes.NewBuffer(requestBody3))
Expand Down
6 changes: 3 additions & 3 deletions utilities/rest/sign/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
package sign

import (
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"testing"

sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
authTypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
)

func Test_SignTx_Request(t *testing.T) {
fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c"
testBaseReq := rest.BaseReq{From: fromAddress, ChainID: "test", Fees: sdkTypes.NewCoins()}

testFee := authTypes.NewStdFee(12, sdkTypes.NewCoins())
testFee := legacytx.NewStdFee(12, sdkTypes.NewCoins())

testStdTx := authTypes.NewStdTx([]sdkTypes.Msg{}, testFee, []authTypes.StdSignature{}, "")
testStdTx := legacytx.NewStdTx([]sdkTypes.Msg{}, testFee, []legacytx.StdSignature{}, "")
require.Equal(t, nil, request{BaseRequest: testBaseReq, Type: "type", StdTx: testStdTx}.Validate())
}
13 changes: 6 additions & 7 deletions utilities/rest/sign/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
package sign

import (
errorConstants "github.com/AssetMantle/modules/helpers/constants"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
authTypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"testing"

errorConstants "github.com/AssetMantle/schema/go/errors/constants"
)

func Test_SignTx_Response(t *testing.T) {
testFee := authTypes.NewStdFee(12, sdkTypes.NewCoins())
testFee := legacytx.NewStdFee(12, sdkTypes.NewCoins())

testStdTx := authTypes.NewStdTx([]sdkTypes.Msg{}, testFee, []authTypes.StdSignature{}, "")
require.Equal(t, response{Success: true, Error: nil, StdTx: testStdTx}, newResponse(testStdTx, nil))
testStdTx := legacytx.NewStdTx([]sdkTypes.Msg{}, testFee, []legacytx.StdSignature{}, "")
require.Equal(t, response{Success: true, Error: nil, Tx: testStdTx}, newResponse(testStdTx, nil))
testResponse := newResponse(testStdTx, errorConstants.IncorrectFormat)
require.Equal(t, false, testResponse.IsSuccessful())
require.Equal(t, errorConstants.IncorrectFormat, testResponse.GetError())
Expand Down

0 comments on commit 01e1137

Please sign in to comment.