Fix TestReissuance() E2E test (#214)

* [lib] Add fee denominator parameter

* [lib] Add client context parameter

e.g. the test cases create their own client context.

* [lib] Reset client context's output

Otherwise if the client context does not change, output gets appended
and gets un-parsable.

* [test] Set missing validator client context values

Necessary for sending transactions.

* [test] Configure RPC library

* [test] Fix `TestReissuance()`

// Closes #195

* Partially revert "[lib] Provide default encoding config (#209)"

This reverts commit 8a8a3aaaf2648f87c4052575bc1a60b23056463b.

Fix README example.

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-12-07 09:57:33 +01:00 committed by GitHub
parent ff6aab33df
commit df8ece2a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 10 deletions

View File

@ -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")

View File

@ -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

View File

@ -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)

View File

@ -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() {

View File

@ -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)