-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* test: add cli_test for query Signed-off-by: 170210 <[email protected]> * test: add cli_test for tx Signed-off-by: 170210 <[email protected]> * chore: lint fix Signed-off-by: 170210 <[email protected]> * chore: update CHANGLOG.md Signed-off-by: 170210 <[email protected]> * chore: lint fix Signed-off-by: 170210 <[email protected]> * test: add grpc query test Signed-off-by: 170210 <[email protected]> * fix: change fromDenom & toDenom Signed-off-by: 170210 <[email protected]> * fix: fix for comment Signed-off-by: 170210 <[email protected]> --------- Signed-off-by: 170210 <[email protected]> (cherry picked from commit 621c03f) Co-authored-by: 170210 <[email protected]>
- Loading branch information
1 parent
ecea330
commit 3e73dfe
Showing
6 changed files
with
884 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build norace | ||
// +build norace | ||
|
||
package testutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/Finschia/finschia-sdk/testutil/network" | ||
) | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
cfg := network.DefaultConfig() | ||
cfg.NumValidators = 1 | ||
suite.Run(t, NewIntegrationTestSuite(cfg)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
|
||
"github.com/Finschia/finschia-sdk/testutil" | ||
"github.com/Finschia/finschia-sdk/testutil/rest" | ||
sdk "github.com/Finschia/finschia-sdk/types" | ||
grpctypes "github.com/Finschia/finschia-sdk/types/grpc" | ||
"github.com/Finschia/finschia-sdk/types/query" | ||
fswaptypes "github.com/Finschia/finschia-sdk/x/fswap/types" | ||
) | ||
|
||
func (s *IntegrationTestSuite) TestGRPCQuerySwap() { | ||
val := s.network.Validators[0] | ||
baseURL := val.APIAddress | ||
|
||
testCases := []struct { | ||
name string | ||
url string | ||
expectedErr bool | ||
expected proto.Message | ||
}{ | ||
{ | ||
"test query swap with valid query string", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swap?from_denom=stake&to_denom=dummy", baseURL), | ||
false, | ||
&fswaptypes.QuerySwapResponse{ | ||
Swap: s.dummySwap, | ||
}, | ||
}, | ||
{ | ||
"test query swap with not existed swap pairs", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swap?from_denom=fake&to_denom=dummy", baseURL), | ||
true, | ||
&fswaptypes.QuerySwapResponse{}, | ||
}, | ||
{ | ||
"test query swap with nil to_denom", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swap?from_denom=stake", baseURL), | ||
true, | ||
&fswaptypes.QuerySwapResponse{}, | ||
}, | ||
{ | ||
"test query swap with nil from_denom", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swap?to_denom=dummy", baseURL), | ||
true, | ||
&fswaptypes.QuerySwapResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
resp, err := rest.GetRequest(tc.url) | ||
s.Require().NoError(err) | ||
var valRes fswaptypes.QuerySwapResponse | ||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &valRes) | ||
|
||
if tc.expectedErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(err) | ||
s.Require().Equal(tc.expected.String(), valRes.String()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestGRPCQuerySwaps() { | ||
val := s.network.Validators[0] | ||
baseURL := val.APIAddress | ||
|
||
testCases := []struct { | ||
name string | ||
url string | ||
expectedErr bool | ||
expected proto.Message | ||
}{ | ||
{ | ||
"test query swaps", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swaps", baseURL), | ||
false, | ||
&fswaptypes.QuerySwapsResponse{ | ||
Swaps: []fswaptypes.Swap{s.dummySwap}, | ||
Pagination: &query.PageResponse{Total: 1}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
resp, err := rest.GetRequest(tc.url) | ||
s.Require().NoError(err) | ||
var valRes fswaptypes.QuerySwapsResponse | ||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &valRes) | ||
|
||
if tc.expectedErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(err) | ||
s.Require().Equal(tc.expected.String(), valRes.String()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestGRPCQuerySwapped() { | ||
val := s.network.Validators[0] | ||
baseURL := val.APIAddress | ||
|
||
testCases := []struct { | ||
name string | ||
url string | ||
expectedErr bool | ||
expected proto.Message | ||
}{ | ||
{ | ||
"test query swapped with valid query string", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swapped?from_denom=stake&to_denom=dummy", baseURL), | ||
false, | ||
&fswaptypes.QuerySwappedResponse{ | ||
FromCoinAmount: sdk.NewCoin("stake", sdk.ZeroInt()), | ||
ToCoinAmount: sdk.NewCoin("dummy", sdk.ZeroInt()), | ||
}, | ||
}, | ||
{ | ||
"test query swapped with not existed swap pairs", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swapped?from_denom=fake&to_denom=dummy", baseURL), | ||
true, | ||
&fswaptypes.QuerySwappedResponse{}, | ||
}, | ||
{ | ||
"test query swapped with nil to_denom", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swapped?from_denom=stake", baseURL), | ||
true, | ||
&fswaptypes.QuerySwappedResponse{}, | ||
}, | ||
{ | ||
"test query swapped with nil from_denom", | ||
fmt.Sprintf("%s/lbm/fswap/v1/swapped?to_denom=dummy", baseURL), | ||
true, | ||
&fswaptypes.QuerySwappedResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
resp, err := testutil.GetRequestWithHeaders(tc.url, map[string]string{ | ||
grpctypes.GRPCBlockHeightHeader: "1", | ||
}) | ||
s.Require().NoError(err) | ||
var valRes fswaptypes.QuerySwappedResponse | ||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &valRes) | ||
|
||
if tc.expectedErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(err) | ||
s.Require().Equal(tc.expected.String(), valRes.String()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestGRPCQueryTotalSwappableAmount() { | ||
val := s.network.Validators[0] | ||
baseURL := val.APIAddress | ||
|
||
testCases := []struct { | ||
name string | ||
url string | ||
expectedErr bool | ||
expected proto.Message | ||
}{ | ||
{ | ||
"test query total_swappable_to_coin_amount with valid query string", | ||
fmt.Sprintf("%s/lbm/fswap/v1/total_swappable_to_coin_amount?from_denom=stake&to_denom=dummy", baseURL), | ||
false, | ||
&fswaptypes.QueryTotalSwappableToCoinAmountResponse{ | ||
SwappableAmount: sdk.NewCoin("dummy", s.dummySwap.AmountCapForToDenom), | ||
}, | ||
}, | ||
{ | ||
"test query total_swappable_to_coin_amount with not existed swap pairs", | ||
fmt.Sprintf("%s/lbm/fswap/v1/total_swappable_to_coin_amount?from_denom=fake&to_denom=dummy", baseURL), | ||
true, | ||
&fswaptypes.QueryTotalSwappableToCoinAmountResponse{}, | ||
}, | ||
{ | ||
"test query total_swappable_to_coin_amount with nil to_denom", | ||
fmt.Sprintf("%s/lbm/fswap/v1/total_swappable_to_coin_amount?from_denom=stake", baseURL), | ||
true, | ||
&fswaptypes.QueryTotalSwappableToCoinAmountResponse{}, | ||
}, | ||
{ | ||
"test query total_swappable_to_coin_amount with nil from_denom", | ||
fmt.Sprintf("%s/lbm/fswap/v1/total_swappable_to_coin_amount?to_denom=dummy", baseURL), | ||
true, | ||
&fswaptypes.QueryTotalSwappableToCoinAmountResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
resp, err := testutil.GetRequestWithHeaders(tc.url, map[string]string{ | ||
grpctypes.GRPCBlockHeightHeader: "1", | ||
}) | ||
s.Require().NoError(err) | ||
var valRes fswaptypes.QueryTotalSwappableToCoinAmountResponse | ||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &valRes) | ||
|
||
if tc.expectedErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(err) | ||
s.Require().Equal(tc.expected.String(), valRes.String()) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.