Jürgen Eckel a29f394bc4
192 migrate config params to on chain module params (#307)
* initial refactoring commit
* added config passing to network creation for some test suits
* fixed refactoring issues
* adjusted params

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
2024-01-30 16:12:04 +01:00

102 lines
2.9 KiB
Go

package asset
import (
"github.com/planetmint/planetmint-go/lib"
"github.com/planetmint/planetmint-go/testutil/network"
"github.com/planetmint/planetmint-go/testutil/sample"
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
assetcli "github.com/planetmint/planetmint-go/x/asset/client/cli"
assettypes "github.com/planetmint/planetmint-go/x/asset/types"
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
// E2ETestSuite struct definition of asset suite
type E2ETestSuite struct {
suite.Suite
cfg network.Config
network *network.Network
}
// NewE2ETestSuite returns configured asset E2ETestSuite
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
return &E2ETestSuite{cfg: cfg}
}
// SetupSuite initializes asset E2ETestSuite
func (s *E2ETestSuite) SetupSuite() {
var daoGenState daotypes.GenesisState
s.cfg.Codec.MustUnmarshalJSON(s.cfg.GenesisState[daotypes.ModuleName], &daoGenState)
daoGenState.Params.FeeDenom = sample.FeeDenom
s.cfg.GenesisState[daotypes.ModuleName] = s.cfg.Codec.MustMarshalJSON(&daoGenState)
s.T().Log("setting up e2e test suite")
s.network = network.New(s.T(), s.cfg)
err := e2etestutil.AttestMachine(s.network, sample.Name, sample.Mnemonic, 0)
s.Require().NoError(err)
}
// TearDownSuite clean up after testing
func (s *E2ETestSuite) TearDownSuite() {
s.T().Log("tearing down e2e test suite")
}
// TestNotarizeAsset notarizes asset over cli
func (s *E2ETestSuite) TestNotarizeAsset() {
val := s.network.Validators[0]
k, err := val.ClientCtx.Keyring.Key(sample.Name)
s.Require().NoError(err)
addr, _ := k.GetAddress()
testCases := []struct {
name string
msg *assettypes.MsgNotarizeAsset
rawLog string
expectCheckTxErr bool
}{
{
"valid notarization",
assettypes.NewMsgNotarizeAsset(addr.String(), sample.Asset()),
"[]",
false,
},
{
"machine not found",
assettypes.NewMsgNotarizeAsset("plmnt1v5394e8vmfrp4qzdav7xkze0f567w3tsgxf09j", sample.Asset()),
"error during CheckTx or ReCheckTx: machine not found",
true,
},
}
for _, tc := range testCases {
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), addr, tc.msg)
if tc.expectCheckTxErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
}
txResponse, err := lib.GetTxResponseFromOut(out)
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
if !tc.expectCheckTxErr {
assert.Equal(s.T(), int(0), int(txResponse.Code))
args := []string{sample.Asset()}
asset, err := clitestutil.ExecTestCLICmd(val.ClientCtx, assetcli.CmdGetByCID(), args)
s.Require().NoError(err)
assert.Contains(s.T(), asset.String(), sample.Asset())
} else {
assert.Contains(s.T(), txResponse.RawLog, tc.rawLog)
}
}
}