diff --git a/lib/README.md b/lib/README.md index 9179217..029ea78 100644 --- a/lib/README.md +++ b/lib/README.md @@ -18,11 +18,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/planetmint/planetmint-go/app" "github.com/planetmint/planetmint-go/lib" ) func main() { + encodingConfig := app.MakeEncodingConfig() + libConfig := lib.GetConfig() + libConfig.SetEncodingConfig(encodingConfig) libConfig.SetRPCEndpoint("https://testnet-rpc.rddl.io:443") addr0 := sdk.MustAccAddressFromBech32("plmnt168z8fyyzap0nw75d4atv9ucr2ye60d57dzlzaf") diff --git a/lib/config.go b/lib/config.go index b747e4d..7f0e76b 100644 --- a/lib/config.go +++ b/lib/config.go @@ -3,6 +3,7 @@ package lib import ( "sync" + "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/planetmint/planetmint-go/lib/params" ) @@ -10,7 +11,9 @@ import ( // Config defines library top level configuration. type Config struct { ChainID string `json:"chain-id" mapstructure:"chain-id"` + ClientCtx client.Context `json:"client-ctx" mapstructure:"client-ctx"` EncodingConfig params.EncodingConfig `json:"encoding-config" mapstructure:"encoding-config"` + FeeDenom string `json:"fee-denom" mapstructure:"fee-denom"` RootDir string `json:"root-dir" mapstructure:"root-dir"` RPCEndpoint string `json:"rpc-endpoint" mapstructure:"rpc-endpoint"` } @@ -26,7 +29,9 @@ var ( func DefaultConfig() *Config { return &Config{ ChainID: "planetmint-testnet-1", + ClientCtx: client.Context{}, EncodingConfig: params.EncodingConfig{}, + FeeDenom: "plmnt", RootDir: "~/.planetmint-go/", RPCEndpoint: "http://127.0.0.1:26657", } @@ -63,6 +68,18 @@ func (config *Config) SetChainID(chainID string) *Config { return config } +// SetClientCtx sets the client context parameter. +func (config *Config) SetClientCtx(clientCtx client.Context) *Config { + config.ClientCtx = clientCtx + return config +} + +// SetFeeDenom sets the fee denominator parameter. +func (config *Config) SetFeeDenom(feeDenom string) *Config { + config.FeeDenom = feeDenom + return config +} + // SetRoot sets the root directory where to find the keyring. func (config *Config) SetRoot(root string) *Config { config.RootDir = root diff --git a/lib/tx.go b/lib/tx.go index c27d571..1e2205e 100644 --- a/lib/tx.go +++ b/lib/tx.go @@ -39,9 +39,14 @@ func getAccountNumberAndSequence(clientCtx client.Context) (accountNumber, seque } func getClientContextAndTxFactory(address sdk.AccAddress) (clientCtx client.Context, txf tx.Factory, err error) { - clientCtx, err = getClientContext(address) - if err != nil { - return + clientCtx = GetConfig().ClientCtx + // at least we need an account retriever + // it would be better to check for an empty client context, but that does not work at the moment + if clientCtx.AccountRetriever == nil { + clientCtx, err = getClientContext(address) + if err != nil { + return + } } accountNumber, sequence, err := getAccountNumberAndSequence(clientCtx) if err != nil { @@ -54,9 +59,10 @@ func getClientContextAndTxFactory(address sdk.AccAddress) (clientCtx client.Cont func getTxFactoryWithAccountNumberAndSequence(clientCtx client.Context, accountNumber, sequence uint64) (txf tx.Factory) { return tx.Factory{}. WithAccountNumber(accountNumber). + WithAccountRetriever(clientCtx.AccountRetriever). WithChainID(clientCtx.ChainID). WithGas(200000). - WithGasPrices("0.000005plmnt"). + WithGasPrices("0.000005" + GetConfig().FeeDenom). WithKeybase(clientCtx.Keyring). WithSequence(sequence). WithTxConfig(clientCtx.TxConfig) @@ -153,6 +159,7 @@ func broadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (bro err = ErrTypeAssertionFailed return } + defer output.Reset() result := make(map[string]interface{}) err = json.Unmarshal(output.Bytes(), &result) diff --git a/tests/e2e/dao/suite.go b/tests/e2e/dao/suite.go index 87fbbb1..a281641 100644 --- a/tests/e2e/dao/suite.go +++ b/tests/e2e/dao/suite.go @@ -49,6 +49,8 @@ func (s *E2ETestSuite) SetupSuite() { // set FeeDenom to node0token because the sending account is initialized with no plmnt tokens conf := config.GetConfig() conf.FeeDenom = "node0token" + // set epochs: make sure to start after initial height of 7 + conf.ReIssuanceEpochs = 25 conf.SetPlanetmintConfig(conf) s.T().Log("setting up e2e test suite") @@ -262,14 +264,27 @@ func (s *E2ETestSuite) TestReissuance() { val := s.network.Validators[0] var err error - for i := 0; i < conf.PopEpochs+10; i++ { - err = s.network.WaitForNextBlock() + latestHeight, err := s.network.LatestHeight() + s.Require().NoError(err) + + var wait int + for { + latestHeight, err = s.network.WaitForHeight(latestHeight + 1) s.Require().NoError(err) + + // wait + for sending the re-issuance result, i.e.: + // block 25: initializing RDDL re-issuance broadcast tx succeeded + // block 26: sending the re-issuance result broadcast tx succeeded + wait = 2 + if latestHeight%int64(conf.ReIssuanceEpochs+wait) == 0 { + break + } } - var height int64 - height, _ = s.network.LatestHeight() - intValue := strconv.FormatInt(height, 10) - _, _ = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetReissuance(), []string{intValue}) + + // - because we waited on the re-issuance result, see above + intValue := strconv.FormatInt(latestHeight-int64(wait), 10) + _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetReissuance(), []string{intValue}) + s.Require().NoError(err) } func (s *E2ETestSuite) TestPoPResult() { diff --git a/testutil/network/network.go b/testutil/network/network.go index 6631102..7838914 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -1,6 +1,7 @@ package network import ( + "bytes" "fmt" "testing" "time" @@ -19,6 +20,7 @@ import ( "github.com/planetmint/planetmint-go/app" "github.com/planetmint/planetmint-go/config" + "github.com/planetmint/planetmint-go/lib" ) type ( @@ -47,6 +49,19 @@ func New(t *testing.T, configs ...Config) *Network { net, err := network.New(t, validatorTmpDir, cfg) appConfig.ValidatorAddress = net.Validators[0].Address.String() + // set missing validator client context values for sending txs + var output bytes.Buffer + net.Validators[0].ClientCtx.BroadcastMode = "sync" + net.Validators[0].ClientCtx.FromAddress = net.Validators[0].Address + net.Validators[0].ClientCtx.FromName = net.Validators[0].Moniker + net.Validators[0].ClientCtx.NodeURI = net.Validators[0].RPCAddress + net.Validators[0].ClientCtx.Output = &output + net.Validators[0].ClientCtx.SkipConfirm = true + + libConfig := lib.GetConfig() + libConfig.SetClientCtx(net.Validators[0].ClientCtx) + libConfig.SetFeeDenom(appConfig.FeeDenom) + libConfig.SetRoot(validatorTmpDir + "/node0/simd") require.NoError(t, err) _, err = net.WaitForHeight(1)