mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
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:
parent
ff6aab33df
commit
df8ece2a30
@ -18,11 +18,15 @@ import (
|
|||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/planetmint/planetmint-go/app"
|
||||||
"github.com/planetmint/planetmint-go/lib"
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
encodingConfig := app.MakeEncodingConfig()
|
||||||
|
|
||||||
libConfig := lib.GetConfig()
|
libConfig := lib.GetConfig()
|
||||||
|
libConfig.SetEncodingConfig(encodingConfig)
|
||||||
libConfig.SetRPCEndpoint("https://testnet-rpc.rddl.io:443")
|
libConfig.SetRPCEndpoint("https://testnet-rpc.rddl.io:443")
|
||||||
|
|
||||||
addr0 := sdk.MustAccAddressFromBech32("plmnt168z8fyyzap0nw75d4atv9ucr2ye60d57dzlzaf")
|
addr0 := sdk.MustAccAddressFromBech32("plmnt168z8fyyzap0nw75d4atv9ucr2ye60d57dzlzaf")
|
||||||
|
@ -3,6 +3,7 @@ package lib
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/planetmint/planetmint-go/lib/params"
|
"github.com/planetmint/planetmint-go/lib/params"
|
||||||
)
|
)
|
||||||
@ -10,7 +11,9 @@ import (
|
|||||||
// Config defines library top level configuration.
|
// Config defines library top level configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ChainID string `json:"chain-id" mapstructure:"chain-id"`
|
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"`
|
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"`
|
RootDir string `json:"root-dir" mapstructure:"root-dir"`
|
||||||
RPCEndpoint string `json:"rpc-endpoint" mapstructure:"rpc-endpoint"`
|
RPCEndpoint string `json:"rpc-endpoint" mapstructure:"rpc-endpoint"`
|
||||||
}
|
}
|
||||||
@ -26,7 +29,9 @@ var (
|
|||||||
func DefaultConfig() *Config {
|
func DefaultConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
ChainID: "planetmint-testnet-1",
|
ChainID: "planetmint-testnet-1",
|
||||||
|
ClientCtx: client.Context{},
|
||||||
EncodingConfig: params.EncodingConfig{},
|
EncodingConfig: params.EncodingConfig{},
|
||||||
|
FeeDenom: "plmnt",
|
||||||
RootDir: "~/.planetmint-go/",
|
RootDir: "~/.planetmint-go/",
|
||||||
RPCEndpoint: "http://127.0.0.1:26657",
|
RPCEndpoint: "http://127.0.0.1:26657",
|
||||||
}
|
}
|
||||||
@ -63,6 +68,18 @@ func (config *Config) SetChainID(chainID string) *Config {
|
|||||||
return 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.
|
// SetRoot sets the root directory where to find the keyring.
|
||||||
func (config *Config) SetRoot(root string) *Config {
|
func (config *Config) SetRoot(root string) *Config {
|
||||||
config.RootDir = root
|
config.RootDir = root
|
||||||
|
15
lib/tx.go
15
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) {
|
func getClientContextAndTxFactory(address sdk.AccAddress) (clientCtx client.Context, txf tx.Factory, err error) {
|
||||||
clientCtx, err = getClientContext(address)
|
clientCtx = GetConfig().ClientCtx
|
||||||
if err != nil {
|
// at least we need an account retriever
|
||||||
return
|
// 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)
|
accountNumber, sequence, err := getAccountNumberAndSequence(clientCtx)
|
||||||
if err != nil {
|
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) {
|
func getTxFactoryWithAccountNumberAndSequence(clientCtx client.Context, accountNumber, sequence uint64) (txf tx.Factory) {
|
||||||
return tx.Factory{}.
|
return tx.Factory{}.
|
||||||
WithAccountNumber(accountNumber).
|
WithAccountNumber(accountNumber).
|
||||||
|
WithAccountRetriever(clientCtx.AccountRetriever).
|
||||||
WithChainID(clientCtx.ChainID).
|
WithChainID(clientCtx.ChainID).
|
||||||
WithGas(200000).
|
WithGas(200000).
|
||||||
WithGasPrices("0.000005plmnt").
|
WithGasPrices("0.000005" + GetConfig().FeeDenom).
|
||||||
WithKeybase(clientCtx.Keyring).
|
WithKeybase(clientCtx.Keyring).
|
||||||
WithSequence(sequence).
|
WithSequence(sequence).
|
||||||
WithTxConfig(clientCtx.TxConfig)
|
WithTxConfig(clientCtx.TxConfig)
|
||||||
@ -153,6 +159,7 @@ func broadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (bro
|
|||||||
err = ErrTypeAssertionFailed
|
err = ErrTypeAssertionFailed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer output.Reset()
|
||||||
|
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
err = json.Unmarshal(output.Bytes(), &result)
|
err = json.Unmarshal(output.Bytes(), &result)
|
||||||
|
@ -49,6 +49,8 @@ func (s *E2ETestSuite) SetupSuite() {
|
|||||||
// set FeeDenom to node0token because the sending account is initialized with no plmnt tokens
|
// set FeeDenom to node0token because the sending account is initialized with no plmnt tokens
|
||||||
conf := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
conf.FeeDenom = "node0token"
|
conf.FeeDenom = "node0token"
|
||||||
|
// set epochs: make sure to start after initial height of 7
|
||||||
|
conf.ReIssuanceEpochs = 25
|
||||||
conf.SetPlanetmintConfig(conf)
|
conf.SetPlanetmintConfig(conf)
|
||||||
|
|
||||||
s.T().Log("setting up e2e test suite")
|
s.T().Log("setting up e2e test suite")
|
||||||
@ -262,14 +264,27 @@ func (s *E2ETestSuite) TestReissuance() {
|
|||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
for i := 0; i < conf.PopEpochs+10; i++ {
|
latestHeight, err := s.network.LatestHeight()
|
||||||
err = s.network.WaitForNextBlock()
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
var wait int
|
||||||
|
for {
|
||||||
|
latestHeight, err = s.network.WaitForHeight(latestHeight + 1)
|
||||||
s.Require().NoError(err)
|
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()
|
// - because we waited on the re-issuance result, see above
|
||||||
intValue := strconv.FormatInt(height, 10)
|
intValue := strconv.FormatInt(latestHeight-int64(wait), 10)
|
||||||
_, _ = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetReissuance(), []string{intValue})
|
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetReissuance(), []string{intValue})
|
||||||
|
s.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *E2ETestSuite) TestPoPResult() {
|
func (s *E2ETestSuite) TestPoPResult() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package network
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/planetmint/planetmint-go/app"
|
"github.com/planetmint/planetmint-go/app"
|
||||||
"github.com/planetmint/planetmint-go/config"
|
"github.com/planetmint/planetmint-go/config"
|
||||||
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -47,6 +49,19 @@ func New(t *testing.T, configs ...Config) *Network {
|
|||||||
net, err := network.New(t, validatorTmpDir, cfg)
|
net, err := network.New(t, validatorTmpDir, cfg)
|
||||||
|
|
||||||
appConfig.ValidatorAddress = net.Validators[0].Address.String()
|
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)
|
require.NoError(t, err)
|
||||||
_, err = net.WaitForHeight(1)
|
_, err = net.WaitForHeight(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user