-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from irisnet/feature/mt
Feature: MT Module
- Loading branch information
Showing
46 changed files
with
13,619 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
package cli_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/tidwall/gjson" | ||
|
||
"github.com/tendermint/tendermint/crypto" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/testutil/network" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
mtcli "github.com/irisnet/irismod/modules/mt/client/cli" | ||
mttestutil "github.com/irisnet/irismod/modules/mt/client/testutil" | ||
mttypes "github.com/irisnet/irismod/modules/mt/types" | ||
"github.com/irisnet/irismod/simapp" | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
|
||
cfg network.Config | ||
network *network.Network | ||
} | ||
|
||
func (s *IntegrationTestSuite) SetupSuite() { | ||
s.T().Log("setting up integration test suite") | ||
|
||
cfg := simapp.NewConfig() | ||
cfg.NumValidators = 2 | ||
|
||
s.cfg = cfg | ||
s.network = network.New(s.T(), cfg) | ||
|
||
_, err := s.network.WaitForHeight(1) | ||
s.Require().NoError(err) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TearDownSuite() { | ||
s.T().Log("tearing down integration test suite") | ||
s.network.Cleanup() | ||
} | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestNft() { | ||
val := s.network.Validators[0] | ||
val2 := s.network.Validators[1] | ||
|
||
// --------------------------------------------------------------------------- | ||
|
||
from := val.Address | ||
data := "data" | ||
mtID := "kitty" | ||
//owner := "owner" | ||
denomName := "name" | ||
denom := "denom" | ||
|
||
//------test GetCmdIssueDenom()------------- | ||
args := []string{ | ||
fmt.Sprintf("--%s=%s", mtcli.FlagName, denomName), | ||
fmt.Sprintf("--%s=%s", mtcli.FlagData, data), | ||
|
||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
|
||
respType := proto.Message(&sdk.TxResponse{}) | ||
expectedCode := uint32(0) | ||
|
||
bz, err := mttestutil.IssueDenomExec(val.ClientCtx, from.String(), denom, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp := respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
denomID := gjson.Get(txResp.RawLog, "0.events.0.attributes.0.value").String() | ||
|
||
//------test GetCmdQueryDenom()------------- | ||
respType = proto.Message(&mttypes.Denom{}) | ||
bz, err = mttestutil.QueryDenomExec(val.ClientCtx, denomID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
denomItem := respType.(*mttypes.Denom) | ||
s.Require().Equal(denomName, denomItem.Name) | ||
s.Require().Equal(data, denomItem.Data) | ||
|
||
//------test GetCmdQueryDenoms()------------- | ||
respType = proto.Message(&mttypes.QueryDenomsResponse{}) | ||
bz, err = mttestutil.QueryDenomsExec(val.ClientCtx) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
denomsResp := respType.(*mttypes.QueryDenomsResponse) | ||
s.Require().Equal(1, len(denomsResp.Denoms)) | ||
s.Require().Equal(denomID, denomsResp.Denoms[0].Id) | ||
|
||
//------test GetCmdMintMT()------------- | ||
args = []string{ | ||
fmt.Sprintf("--%s=%s", mtcli.FlagData, data), | ||
fmt.Sprintf("--%s=%s", mtcli.FlagRecipient, from.String()), | ||
|
||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
|
||
respType = proto.Message(&sdk.TxResponse{}) | ||
|
||
bz, err = mttestutil.MintMTExec(val.ClientCtx, from.String(), denomID, mtID, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp = respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
//------test GetCmdQuerySupply()------------- | ||
respType = proto.Message(&mttypes.QuerySupplyResponse{}) | ||
bz, err = mttestutil.QuerySupplyExec(val.ClientCtx, denomID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
supplyResp := respType.(*mttypes.QuerySupplyResponse) | ||
s.Require().Equal(uint64(1), supplyResp.Amount) | ||
|
||
//------test GetCmdQueryMT()------------- | ||
respType = proto.Message(&mttypes.MT{}) | ||
bz, err = mttestutil.QueryMTExec(val.ClientCtx, denomID, mtID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
mtItem := respType.(*mttypes.MT) | ||
s.Require().Equal(mtID, mtItem.Id) | ||
s.Require().Equal(data, mtItem.Data) | ||
|
||
//------test GetCmdEditMT()------------- | ||
newTokenDate := "newdata" | ||
args = []string{ | ||
fmt.Sprintf("--%s=%s", mtcli.FlagData, newTokenDate), | ||
|
||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
|
||
respType = proto.Message(&sdk.TxResponse{}) | ||
|
||
bz, err = mttestutil.EditMTExec(val.ClientCtx, from.String(), denomID, mtID, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp = respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
respType = proto.Message(&mttypes.MT{}) | ||
bz, err = mttestutil.QueryMTExec(val.ClientCtx, denomID, mtID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
newNftItem := respType.(*mttypes.MT) | ||
s.Require().Equal(newTokenDate, newNftItem.Data) | ||
|
||
//------test GetCmdTransferMT()------------- | ||
recipient := sdk.AccAddress(crypto.AddressHash([]byte("dgsbl"))) | ||
|
||
args = []string{ | ||
fmt.Sprintf("--%s=%s", mtcli.FlagData, data), | ||
|
||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
|
||
respType = proto.Message(&sdk.TxResponse{}) | ||
|
||
bz, err = mttestutil.TransferMTExec(val.ClientCtx, from.String(), recipient.String(), denomID, mtID, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp = respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
respType = proto.Message(&mttypes.MT{}) | ||
bz, err = mttestutil.QueryMTExec(val.ClientCtx, denomID, mtID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
mtItem = respType.(*mttypes.MT) | ||
s.Require().Equal(mtID, mtItem.Id) | ||
s.Require().Equal(data, mtItem.Data) | ||
|
||
//------test GetCmdBurnMT()------------- | ||
newMTID := "dgsbl" | ||
args = []string{ | ||
fmt.Sprintf("--%s=%s", mtcli.FlagData, newTokenDate), | ||
fmt.Sprintf("--%s=%s", mtcli.FlagRecipient, from.String()), | ||
|
||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
|
||
respType = proto.Message(&sdk.TxResponse{}) | ||
|
||
bz, err = mttestutil.MintMTExec(val.ClientCtx, from.String(), denomID, newMTID, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp = respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
respType = proto.Message(&mttypes.QuerySupplyResponse{}) | ||
bz, err = mttestutil.QuerySupplyExec(val.ClientCtx, denomID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
supplyResp = respType.(*mttypes.QuerySupplyResponse) | ||
s.Require().Equal(uint64(2), supplyResp.Amount) | ||
|
||
args = []string{ | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
respType = proto.Message(&sdk.TxResponse{}) | ||
bz, err = mttestutil.BurnMTExec(val.ClientCtx, from.String(), denomID, newMTID, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val2.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp = respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
respType = proto.Message(&mttypes.QuerySupplyResponse{}) | ||
bz, err = mttestutil.QuerySupplyExec(val.ClientCtx, denomID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
supplyResp = respType.(*mttypes.QuerySupplyResponse) | ||
s.Require().Equal(uint64(1), supplyResp.Amount) | ||
|
||
//------test GetCmdTransferDenom()------------- | ||
args = []string{ | ||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), | ||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), | ||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()), | ||
} | ||
|
||
respType = proto.Message(&sdk.TxResponse{}) | ||
|
||
bz, err = mttestutil.TransferDenomExec(val.ClientCtx, from.String(), val2.Address.String(), denomID, args...) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) | ||
txResp = respType.(*sdk.TxResponse) | ||
s.Require().Equal(expectedCode, txResp.Code) | ||
|
||
respType = proto.Message(&mttypes.Denom{}) | ||
bz, err = mttestutil.QueryDenomExec(val.ClientCtx, denomID) | ||
s.Require().NoError(err) | ||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) | ||
denomItem2 := respType.(*mttypes.Denom) | ||
s.Require().Equal(val2.Address.String(), denomItem2.Owner) | ||
s.Require().Equal(denomName, denomItem2.Name) | ||
} |
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,34 @@ | ||
package cli | ||
|
||
import ( | ||
flag "github.com/spf13/pflag" | ||
) | ||
|
||
const ( | ||
FlagRecipient = "recipient" | ||
FlagData = "data" | ||
FlagName = "name" | ||
FlagMTID = "mt-id" | ||
FlagAmount = "amount" | ||
) | ||
|
||
var ( | ||
FsIssueDenom = flag.NewFlagSet("", flag.ContinueOnError) | ||
FsTransferDenom = flag.NewFlagSet("", flag.ContinueOnError) | ||
|
||
FsMintMT = flag.NewFlagSet("", flag.ContinueOnError) | ||
FsEditMT = flag.NewFlagSet("", flag.ContinueOnError) | ||
FsTransferMT = flag.NewFlagSet("", flag.ContinueOnError) | ||
) | ||
|
||
func init() { | ||
FsIssueDenom.String(FlagName, "", "The name of the denom") | ||
FsIssueDenom.String(FlagData, "", "The metadata of the denom") | ||
|
||
FsMintMT.String(FlagMTID, "", "The ID of the MT, leave empty when issuing, required when minting") | ||
FsMintMT.String(FlagAmount, "1", "The amount of the MT to mint") | ||
FsMintMT.String(FlagData, "", "The metadata of the MT") | ||
FsMintMT.String(FlagRecipient, "", "The recipient of the MT, default to the sender of the tx") | ||
|
||
FsEditMT.String(FlagData, "[do-not-modify]", "The metadata of the MT") | ||
} |
Oops, something went wrong.