feat: decouple x/nft from simapp (#12233)

This commit is contained in:
Julien Robert
2022-06-14 08:32:12 +02:00
committed by GitHub
parent b786d5dea8
commit df41b6563c
17 changed files with 469 additions and 256 deletions
-1
View File
@@ -1,7 +1,6 @@
package testutil
import (
_ "embed"
"testing"
"github.com/stretchr/testify/require"
+4 -4
View File
@@ -219,7 +219,7 @@ func (s *TestSuite) TestSupply() {
Id: testID,
Uri: testURI,
}
err := s.app.NFTKeeper.Mint(s.ctx, n, s.addrs[0])
err := s.nftKeeper.Mint(s.ctx, n, s.addrs[0])
require.NoError(err, "the error occurred on:%d", index)
req = &nft.QuerySupplyRequest{
@@ -292,7 +292,7 @@ func (s *TestSuite) TestNFTs() {
Id: testID,
Uri: testURI,
}
err := s.app.NFTKeeper.Mint(s.ctx, n, s.addrs[0])
err := s.nftKeeper.Mint(s.ctx, n, s.addrs[0])
require.NoError(err, "the error occurred on:%d", index)
},
"",
@@ -303,7 +303,7 @@ func (s *TestSuite) TestNFTs() {
{
"Success,query by owner",
func(index int, require *require.Assertions) {
err := s.app.NFTKeeper.SaveClass(s.ctx, nft.Class{
err := s.nftKeeper.SaveClass(s.ctx, nft.Class{
Id: "MyKitty",
})
require.NoError(err)
@@ -314,7 +314,7 @@ func (s *TestSuite) TestNFTs() {
ClassId: "MyKitty",
Id: fmt.Sprintf("MyCat%d", i),
}
err := s.app.NFTKeeper.Mint(s.ctx, n, s.addrs[2])
err := s.nftKeeper.Mint(s.ctx, n, s.addrs[2])
require.NoError(err)
nfts = append(nfts, &n)
}
+72 -53
View File
@@ -8,9 +8,14 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/nft"
"github.com/cosmos/cosmos-sdk/x/nft/keeper"
"github.com/cosmos/cosmos-sdk/x/nft/testutil"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)
const (
@@ -28,24 +33,38 @@ const (
type TestSuite struct {
suite.Suite
app *simapp.SimApp
ctx sdk.Context
addrs []sdk.AccAddress
queryClient nft.QueryClient
nftKeeper keeper.Keeper
}
func (s *TestSuite) SetupTest() {
app := simapp.Setup(s.T(), false)
var (
interfaceRegistry codectypes.InterfaceRegistry
bankKeeper bankkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
nftKeeper keeper.Keeper
)
app, err := simtestutil.Setup(
testutil.AppConfig,
&interfaceRegistry,
&nftKeeper,
&bankKeeper,
&stakingKeeper,
)
s.Require().NoError(err)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()})
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
nft.RegisterQueryServer(queryHelper, app.NFTKeeper)
queryClient := nft.NewQueryClient(queryHelper)
queryHelper := baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry)
nft.RegisterQueryServer(queryHelper, nftKeeper)
s.app = app
s.ctx = ctx
s.queryClient = queryClient
s.addrs = simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(30000000))
s.queryClient = nft.NewQueryClient(queryHelper)
s.addrs = simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 3, sdk.NewInt(30000000))
s.nftKeeper = nftKeeper
}
func TestTestSuite(t *testing.T) {
@@ -61,14 +80,14 @@ func (s *TestSuite) TestSaveClass() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, except)
err := s.nftKeeper.SaveClass(s.ctx, except)
s.Require().NoError(err)
actual, has := s.app.NFTKeeper.GetClass(s.ctx, testClassID)
actual, has := s.nftKeeper.GetClass(s.ctx, testClassID)
s.Require().True(has)
s.Require().EqualValues(except, actual)
classes := s.app.NFTKeeper.GetClasses(s.ctx)
classes := s.nftKeeper.GetClasses(s.ctx)
s.Require().EqualValues([]*nft.Class{&except}, classes)
}
@@ -81,7 +100,7 @@ func (s *TestSuite) TestUpdateClass() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, class)
err := s.nftKeeper.SaveClass(s.ctx, class)
s.Require().NoError(err)
noExistClass := nft.Class{
@@ -93,7 +112,7 @@ func (s *TestSuite) TestUpdateClass() {
UriHash: testClassURIHash,
}
err = s.app.NFTKeeper.UpdateClass(s.ctx, noExistClass)
err = s.nftKeeper.UpdateClass(s.ctx, noExistClass)
s.Require().Error(err)
s.Require().Contains(err.Error(), "nft class does not exist")
@@ -106,10 +125,10 @@ func (s *TestSuite) TestUpdateClass() {
UriHash: testClassURIHash,
}
err = s.app.NFTKeeper.UpdateClass(s.ctx, except)
err = s.nftKeeper.UpdateClass(s.ctx, except)
s.Require().NoError(err)
actual, has := s.app.NFTKeeper.GetClass(s.ctx, testClassID)
actual, has := s.nftKeeper.GetClass(s.ctx, testClassID)
s.Require().True(has)
s.Require().EqualValues(except, actual)
}
@@ -123,7 +142,7 @@ func (s *TestSuite) TestMint() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, class)
err := s.nftKeeper.SaveClass(s.ctx, class)
s.Require().NoError(err)
expNFT := nft.NFT{
@@ -131,32 +150,32 @@ func (s *TestSuite) TestMint() {
Id: testID,
Uri: testURI,
}
err = s.app.NFTKeeper.Mint(s.ctx, expNFT, s.addrs[0])
err = s.nftKeeper.Mint(s.ctx, expNFT, s.addrs[0])
s.Require().NoError(err)
// test GetNFT
actNFT, has := s.app.NFTKeeper.GetNFT(s.ctx, testClassID, testID)
actNFT, has := s.nftKeeper.GetNFT(s.ctx, testClassID, testID)
s.Require().True(has)
s.Require().EqualValues(expNFT, actNFT)
// test GetOwner
owner := s.app.NFTKeeper.GetOwner(s.ctx, testClassID, testID)
owner := s.nftKeeper.GetOwner(s.ctx, testClassID, testID)
s.Require().True(s.addrs[0].Equals(owner))
// test GetNFTsOfClass
actNFTs := s.app.NFTKeeper.GetNFTsOfClass(s.ctx, testClassID)
actNFTs := s.nftKeeper.GetNFTsOfClass(s.ctx, testClassID)
s.Require().EqualValues([]nft.NFT{expNFT}, actNFTs)
// test GetNFTsOfClassByOwner
actNFTs = s.app.NFTKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[0])
actNFTs = s.nftKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[0])
s.Require().EqualValues([]nft.NFT{expNFT}, actNFTs)
// test GetBalance
balance := s.app.NFTKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
balance := s.nftKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
s.Require().EqualValues(uint64(1), balance)
// test GetTotalSupply
supply := s.app.NFTKeeper.GetTotalSupply(s.ctx, testClassID)
supply := s.nftKeeper.GetTotalSupply(s.ctx, testClassID)
s.Require().EqualValues(uint64(1), supply)
expNFT2 := nft.NFT{
@@ -164,15 +183,15 @@ func (s *TestSuite) TestMint() {
Id: testID + "2",
Uri: testURI + "2",
}
err = s.app.NFTKeeper.Mint(s.ctx, expNFT2, s.addrs[0])
err = s.nftKeeper.Mint(s.ctx, expNFT2, s.addrs[0])
s.Require().NoError(err)
// test GetNFTsOfClassByOwner
actNFTs = s.app.NFTKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[0])
actNFTs = s.nftKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[0])
s.Require().EqualValues([]nft.NFT{expNFT, expNFT2}, actNFTs)
// test GetBalance
balance = s.app.NFTKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
balance = s.nftKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
s.Require().EqualValues(uint64(2), balance)
}
@@ -185,7 +204,7 @@ func (s *TestSuite) TestBurn() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, except)
err := s.nftKeeper.SaveClass(s.ctx, except)
s.Require().NoError(err)
expNFT := nft.NFT{
@@ -193,34 +212,34 @@ func (s *TestSuite) TestBurn() {
Id: testID,
Uri: testURI,
}
err = s.app.NFTKeeper.Mint(s.ctx, expNFT, s.addrs[0])
err = s.nftKeeper.Mint(s.ctx, expNFT, s.addrs[0])
s.Require().NoError(err)
err = s.app.NFTKeeper.Burn(s.ctx, testClassID, testID)
err = s.nftKeeper.Burn(s.ctx, testClassID, testID)
s.Require().NoError(err)
// test GetNFT
_, has := s.app.NFTKeeper.GetNFT(s.ctx, testClassID, testID)
_, has := s.nftKeeper.GetNFT(s.ctx, testClassID, testID)
s.Require().False(has)
// test GetOwner
owner := s.app.NFTKeeper.GetOwner(s.ctx, testClassID, testID)
owner := s.nftKeeper.GetOwner(s.ctx, testClassID, testID)
s.Require().Nil(owner)
// test GetNFTsOfClass
actNFTs := s.app.NFTKeeper.GetNFTsOfClass(s.ctx, testClassID)
actNFTs := s.nftKeeper.GetNFTsOfClass(s.ctx, testClassID)
s.Require().Empty(actNFTs)
// test GetNFTsOfClassByOwner
actNFTs = s.app.NFTKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[0])
actNFTs = s.nftKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[0])
s.Require().Empty(actNFTs)
// test GetBalance
balance := s.app.NFTKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
balance := s.nftKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
s.Require().EqualValues(uint64(0), balance)
// test GetTotalSupply
supply := s.app.NFTKeeper.GetTotalSupply(s.ctx, testClassID)
supply := s.nftKeeper.GetTotalSupply(s.ctx, testClassID)
s.Require().EqualValues(uint64(0), supply)
}
@@ -233,7 +252,7 @@ func (s *TestSuite) TestUpdate() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, class)
err := s.nftKeeper.SaveClass(s.ctx, class)
s.Require().NoError(err)
myNFT := nft.NFT{
@@ -241,7 +260,7 @@ func (s *TestSuite) TestUpdate() {
Id: testID,
Uri: testURI,
}
err = s.app.NFTKeeper.Mint(s.ctx, myNFT, s.addrs[0])
err = s.nftKeeper.Mint(s.ctx, myNFT, s.addrs[0])
s.Require().NoError(err)
expNFT := nft.NFT{
@@ -250,11 +269,11 @@ func (s *TestSuite) TestUpdate() {
Uri: "updated",
}
err = s.app.NFTKeeper.Update(s.ctx, expNFT)
err = s.nftKeeper.Update(s.ctx, expNFT)
s.Require().NoError(err)
// test GetNFT
actNFT, has := s.app.NFTKeeper.GetNFT(s.ctx, testClassID, testID)
actNFT, has := s.nftKeeper.GetNFT(s.ctx, testClassID, testID)
s.Require().True(has)
s.Require().EqualValues(expNFT, actNFT)
}
@@ -268,7 +287,7 @@ func (s *TestSuite) TestTransfer() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, class)
err := s.nftKeeper.SaveClass(s.ctx, class)
s.Require().NoError(err)
expNFT := nft.NFT{
@@ -276,25 +295,25 @@ func (s *TestSuite) TestTransfer() {
Id: testID,
Uri: testURI,
}
err = s.app.NFTKeeper.Mint(s.ctx, expNFT, s.addrs[0])
err = s.nftKeeper.Mint(s.ctx, expNFT, s.addrs[0])
s.Require().NoError(err)
// valid owner
err = s.app.NFTKeeper.Transfer(s.ctx, testClassID, testID, s.addrs[1])
err = s.nftKeeper.Transfer(s.ctx, testClassID, testID, s.addrs[1])
s.Require().NoError(err)
// test GetOwner
owner := s.app.NFTKeeper.GetOwner(s.ctx, testClassID, testID)
owner := s.nftKeeper.GetOwner(s.ctx, testClassID, testID)
s.Require().Equal(s.addrs[1], owner)
balanceAddr0 := s.app.NFTKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
balanceAddr0 := s.nftKeeper.GetBalance(s.ctx, testClassID, s.addrs[0])
s.Require().EqualValues(uint64(0), balanceAddr0)
balanceAddr1 := s.app.NFTKeeper.GetBalance(s.ctx, testClassID, s.addrs[1])
balanceAddr1 := s.nftKeeper.GetBalance(s.ctx, testClassID, s.addrs[1])
s.Require().EqualValues(uint64(1), balanceAddr1)
// test GetNFTsOfClassByOwner
actNFTs := s.app.NFTKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[1])
actNFTs := s.nftKeeper.GetNFTsOfClassByOwner(s.ctx, testClassID, s.addrs[1])
s.Require().EqualValues([]nft.NFT{expNFT}, actNFTs)
}
@@ -307,7 +326,7 @@ func (s *TestSuite) TestExportGenesis() {
Uri: testClassURI,
UriHash: testClassURIHash,
}
err := s.app.NFTKeeper.SaveClass(s.ctx, class)
err := s.nftKeeper.SaveClass(s.ctx, class)
s.Require().NoError(err)
expNFT := nft.NFT{
@@ -315,7 +334,7 @@ func (s *TestSuite) TestExportGenesis() {
Id: testID,
Uri: testURI,
}
err = s.app.NFTKeeper.Mint(s.ctx, expNFT, s.addrs[0])
err = s.nftKeeper.Mint(s.ctx, expNFT, s.addrs[0])
s.Require().NoError(err)
expGenesis := &nft.GenesisState{
@@ -325,7 +344,7 @@ func (s *TestSuite) TestExportGenesis() {
Nfts: []*nft.NFT{&expNFT},
}},
}
genesis := s.app.NFTKeeper.ExportGenesis(s.ctx)
genesis := s.nftKeeper.ExportGenesis(s.ctx)
s.Require().Equal(expGenesis, genesis)
}
@@ -350,14 +369,14 @@ func (s *TestSuite) TestInitGenesis() {
Nfts: []*nft.NFT{&expNFT},
}},
}
s.app.NFTKeeper.InitGenesis(s.ctx, expGenesis)
s.nftKeeper.InitGenesis(s.ctx, expGenesis)
actual, has := s.app.NFTKeeper.GetClass(s.ctx, testClassID)
actual, has := s.nftKeeper.GetClass(s.ctx, testClassID)
s.Require().True(has)
s.Require().EqualValues(expClass, actual)
// test GetNFT
actNFT, has := s.app.NFTKeeper.GetNFT(s.ctx, testClassID, testID)
actNFT, has := s.nftKeeper.GetNFT(s.ctx, testClassID, testID)
s.Require().True(has)
s.Require().EqualValues(expNFT, actNFT)
}
+3 -5
View File
@@ -20,7 +20,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
modulev1 "cosmossdk.io/api/cosmos/nft/module/v1"
"github.com/cosmos/cosmos-sdk/x/nft"
@@ -218,17 +217,16 @@ type nftInputs struct {
Key *store.KVStoreKey
Cdc codec.Codec
Subspace paramstypes.Subspace
Registry cdctypes.InterfaceRegistry
AccountKeeper nft.AccountKeeper `key:"cosmos.auth.v1.AccountKeeper"`
BankKeeper nft.BankKeeper `key:"cosmos.bank.v1.Keeper"`
AccountKeeper nft.AccountKeeper
BankKeeper nft.BankKeeper
}
type nftOutputs struct {
depinject.Out
NFTKeeper keeper.Keeper `key:"cosmos.nft.v1.Keeper"`
NFTKeeper keeper.Keeper
Module runtime.AppModuleWrapper
}
+5 -2
View File
@@ -6,13 +6,15 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/depinject"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/nft"
"github.com/cosmos/cosmos-sdk/x/nft/keeper"
"github.com/cosmos/cosmos-sdk/x/nft/simulation"
"github.com/cosmos/cosmos-sdk/x/nft/testutil"
)
var (
@@ -21,7 +23,8 @@ var (
)
func TestDecodeStore(t *testing.T) {
cdc := simapp.MakeTestEncodingConfig().Codec
var cdc codec.Codec
depinject.Inject(testutil.AppConfig, &cdc)
dec := simulation.NewDecodeStore(cdc)
class := nft.Class{
+6 -3
View File
@@ -8,22 +8,25 @@ import (
"github.com/stretchr/testify/require"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/depinject"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/nft"
"github.com/cosmos/cosmos-sdk/x/nft/simulation"
"github.com/cosmos/cosmos-sdk/x/nft/testutil"
)
func TestRandomizedGenState(t *testing.T) {
app := simapp.Setup(t, false)
var cdc codec.Codec
depinject.Inject(testutil.AppConfig, &cdc)
s := rand.NewSource(1)
r := rand.New(s)
simState := module.SimulationState{
AppParams: make(simtypes.AppParams),
Cdc: app.AppCodec(),
Cdc: cdc,
Rand: r,
NumBonded: 3,
Accounts: simtypes.RandomAccounts(r, 3),
+2 -2
View File
@@ -7,9 +7,9 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/cosmos-sdk/x/nft"
"github.com/cosmos/cosmos-sdk/x/nft/keeper"
@@ -96,7 +96,7 @@ func SimulateMsgSend(
Receiver: receiver.Address.String(),
}
txCfg := simappparams.MakeTestEncodingConfig().TxConfig
txCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes)
tx, err := helpers.GenSignedMockTx(
txCfg,
[]sdk.Msg{msg},
+42 -18
View File
@@ -11,35 +11,59 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/cosmos/cosmos-sdk/x/nft"
nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper"
"github.com/cosmos/cosmos-sdk/x/nft/simulation"
"github.com/cosmos/cosmos-sdk/x/nft/testutil"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)
type SimTestSuite struct {
suite.Suite
ctx sdk.Context
app *simapp.SimApp
app *runtime.App
codec codec.Codec
interfaceRegistry codectypes.InterfaceRegistry
accountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
nftKeeper nftkeeper.Keeper
}
func (suite *SimTestSuite) SetupTest() {
checkTx := false
app := simapp.Setup(suite.T(), checkTx)
app, err := simtestutil.Setup(
testutil.AppConfig,
&suite.codec,
&suite.interfaceRegistry,
&suite.accountKeeper,
&suite.bankKeeper,
&suite.stakingKeeper,
&suite.nftKeeper,
)
suite.Require().NoError(err)
suite.app = app
suite.ctx = app.BaseApp.NewContext(checkTx, tmproto.Header{})
suite.ctx = app.BaseApp.NewContext(false, tmproto.Header{})
}
func (suite *SimTestSuite) TestWeightedOperations() {
weightedOps := simulation.WeightedOperations(
suite.app.InterfaceRegistry(),
suite.interfaceRegistry,
make(simtypes.AppParams),
suite.app.AppCodec(),
suite.app.AccountKeeper,
suite.app.BankKeeper, suite.app.NFTKeeper,
suite.codec,
suite.accountKeeper,
suite.bankKeeper,
suite.nftKeeper,
)
// setup 3 accounts
@@ -61,7 +85,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
// by WeightedOperations. if the ordering in WeightedOperations changes some tests
// will fail
suite.Require().Equal(expected[i].weight, w.Weight(), "weight should be the same")
suite.Require().Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same")
suite.Require().Contains(expected[i].opMsgRoute, operationMsg.Route, "route should be the same")
suite.Require().Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same")
}
}
@@ -69,14 +93,14 @@ func (suite *SimTestSuite) TestWeightedOperations() {
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
accounts := simtypes.RandomAccounts(r, n)
initAmt := suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 200000)
initAmt := suite.stakingKeeper.TokensFromConsensusPower(suite.ctx, 200000)
initCoins := sdk.NewCoins(sdk.NewCoin("stake", initAmt))
// add coins to the accounts
for _, account := range accounts {
acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.app.AccountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(testutil.FundAccount(suite.app.BankKeeper, suite.ctx, account.Address, initCoins))
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
}
return accounts
@@ -98,13 +122,13 @@ func (suite *SimTestSuite) TestSimulateMsgSend() {
})
// execute operation
registry := suite.app.InterfaceRegistry()
op := simulation.SimulateMsgSend(codec.NewProtoCodec(registry), suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.NFTKeeper)
registry := suite.interfaceRegistry
op := simulation.SimulateMsgSend(codec.NewProtoCodec(registry), suite.accountKeeper, suite.bankKeeper, suite.nftKeeper)
operationMsg, futureOperations, err := op(r, suite.app.BaseApp, ctx, accounts, "")
suite.Require().NoError(err)
var msg nft.MsgSend
suite.app.AppCodec().UnmarshalJSON(operationMsg.Msg, &msg)
suite.codec.UnmarshalJSON(operationMsg.Msg, &msg)
suite.Require().True(operationMsg.OK)
suite.Require().Len(futureOperations, 0)
}
+6
View File
@@ -11,3 +11,9 @@ order: 1
## NFT
The full name of NFT is Non-Fungible Tokens. Because of the irreplaceable nature of NFT, it means that it can be used to represent unique things. The nft implemented by this module is fully compatible with Ethereum ERC721 standard.
## App Wiring
The minimal app-wiring configuration for this `x/nft` is as follows:
+++ https://github.com/cosmos/cosmos-sdk/blob/main/x/nft/testutil/app.yaml
+14 -8
View File
@@ -3,11 +3,11 @@ modules:
config:
"@type": cosmos.app.runtime.v1alpha1.Module
app_name: NftApp
app_name: NFTApp
begin_blockers: [staking, auth, bank, genutil, nft, params]
end_blockers: [staking, auth, bank, genutil, nft, params]
init_genesis: [auth, bank, staking, genutil, nft, params]
begin_blockers: [mint, staking, auth, bank, mint, genutil, nft, params]
end_blockers: [mint, staking, auth, bank, mint, genutil, nft, params]
init_genesis: [auth, bank, mint, staking, mint, genutil, nft, params]
- name: auth
config:
@@ -15,6 +15,8 @@ modules:
bech32_prefix: cosmos
module_account_permissions:
- account: fee_collector
- account: mint
permissions: [minter]
- account: bonded_tokens_pool
permissions: [burner, staking]
- account: not_bonded_tokens_pool
@@ -33,10 +35,6 @@ modules:
config:
"@type": cosmos.tx.module.v1.Module
- name: nft
config:
"@type": cosmos.nft.module.v1.Module
- name: staking
config:
"@type": cosmos.staking.module.v1.Module
@@ -44,3 +42,11 @@ modules:
- name: genutil
config:
"@type": cosmos.genutil.module.v1.Module
- name: mint
config:
"@type": cosmos.mint.module.v1.Module
- name: nft
config:
"@type": cosmos.nft.module.v1.Module
+8
View File
@@ -4,6 +4,14 @@ import (
_ "embed"
"cosmossdk.io/core/appconfig"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
_ "github.com/cosmos/cosmos-sdk/x/bank"
_ "github.com/cosmos/cosmos-sdk/x/genutil"
_ "github.com/cosmos/cosmos-sdk/x/mint"
_ "github.com/cosmos/cosmos-sdk/x/nft/module"
_ "github.com/cosmos/cosmos-sdk/x/params"
_ "github.com/cosmos/cosmos-sdk/x/staking"
)
//go:embed app.yaml