Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix tests after qgb changes #133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const (
// Tendermint logging flags
FlagLogLevel = "log_level"
FlagLogFormat = "log_format"

// QGB related flags
FlagOrchestratorAddress = "orchestrator-address"
FlagEthereumAddress = "ethereum-address"
)

// LineBreak can be included in a command list to provide a blank line
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/cosmos/iavl v0.17.1
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25
github.com/ethereum/go-ethereum v1.9.25
github.com/gogo/gateway v1.1.0
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25 h1:2vLKys4RBU4
github.com/enigmampc/btcutil v1.0.3-0.20200723161021-e2fb6adb2a25/go.mod h1:hTr8+TLQmkUkgcuh3mcr5fjrT9c64ZzsBCdCEC6UppY=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.9.25 h1:mMiw/zOOtCLdGLWfcekua0qPrJTe7FVIiHJ4IKNTfR0=
github.com/ethereum/go-ethereum v1.9.25/go.mod h1:vMkFiYLHI4tgPw4k2j4MHKoovchFE8plZ0M9VMk4/oM=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
Expand Down
15 changes: 10 additions & 5 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -76,7 +77,8 @@ Example:

return InitTestnet(
clientCtx, cmd, config, mbm, genBalIterator, outputDir, chainID, minGasPrices,
nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo, numValidators,
nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo,
numValidators,
)
},
}
Expand Down Expand Up @@ -206,9 +208,12 @@ func InitTestnet(
genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))

// TODO make these come from the test command
orchAddr, _ := sdk.AccAddressFromBech32("celes1qktu8009djs6uym9uwj84ead24exkezsaqrmn5")
ethAddr, _ := stakingtypes.NewEthAddress("0x91DEd26b5f38B065FC0204c7929Da6b2A21277Cd")
orchAddress := sdk.AccAddress(valPubKeys[i].Address())

ethAddress, err := teststaking.RandomEthAddress()
if err != nil {
return err
}

valTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
createValMsg, err := stakingtypes.NewMsgCreateValidator(
Expand All @@ -217,7 +222,7 @@ func InitTestnet(
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(), orchAddr, *ethAddr,
sdk.OneInt(), orchAddress, *ethAddress,
)
if err != nil {
return err
Expand Down
45 changes: 30 additions & 15 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package network
import (
"bufio"
"context"
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -162,6 +164,11 @@ type (
api *api.Server
grpc *grpc.Server
grpcWeb *http.Server

EthPrivateKey *ecdsa.PrivateKey
EthereumAddr *stakingtypes.EthAddress

OrchestratorAddr sdk.AccAddress
}
)

Expand Down Expand Up @@ -303,16 +310,21 @@ func New(t *testing.T, cfg Config) *Network {
commission, err := sdk.NewDecFromStr("0.5")
require.NoError(t, err)

orchAddr, _ := sdk.AccAddressFromHex("celes1qktu8009djs6uym9uwj84ead24exkezsaqrmn5")
ethAddr, _ := stakingtypes.NewEthAddress("0x91DEd26b5f38B065FC0204c7929Da6b2A21277Cd")
ethPrivateKey, err := crypto.GenerateKey()
require.NoError(t, err)
orchEthPublicKey := ethPrivateKey.Public().(*ecdsa.PublicKey)
ethAddr, err := stakingtypes.NewEthAddress(crypto.PubkeyToAddress(*orchEthPublicKey).Hex())
require.NoError(t, err)

createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(), orchAddr, *ethAddr,
sdk.OneInt(),
addr,
*ethAddr,
)
require.NoError(t, err)

Expand Down Expand Up @@ -355,18 +367,21 @@ func New(t *testing.T, cfg Config) *Network {
WithAccountRetriever(cfg.AccountRetriever)

network.Validators[i] = &Validator{
AppConfig: appCfg,
ClientCtx: clientCtx,
Ctx: ctx,
Dir: filepath.Join(network.BaseDir, nodeDirName),
NodeID: nodeID,
PubKey: pubKey,
Moniker: nodeDirName,
RPCAddress: tmCfg.RPC.ListenAddress,
P2PAddress: tmCfg.P2P.ListenAddress,
APIAddress: apiAddr,
Address: addr,
ValAddress: sdk.ValAddress(addr),
AppConfig: appCfg,
ClientCtx: clientCtx,
Ctx: ctx,
Dir: filepath.Join(network.BaseDir, nodeDirName),
NodeID: nodeID,
PubKey: pubKey,
Moniker: nodeDirName,
RPCAddress: tmCfg.RPC.ListenAddress,
P2PAddress: tmCfg.P2P.ListenAddress,
APIAddress: apiAddr,
Address: addr,
ValAddress: sdk.ValAddress(addr),
EthPrivateKey: ethPrivateKey,
EthereumAddr: ethAddr,
OrchestratorAddr: addr,
}
}

Expand Down
11 changes: 9 additions & 2 deletions x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,18 @@ func (s *IntegrationTestSuite) TestCLIQueryTxsCmdByEvents() {
name string
args []string
expectEmpty bool
expectError string
}{
{
{ // Multiple shares failing test
"fee event happy case",
[]string{
fmt.Sprintf("--events=tx.fee=%s",
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
false,
"transaction spanned more than two shares, this is not yet supported",
// TODO: change this to not expect an error when functionality is added to celestia-core
},
{
"no matching fee event",
Expand All @@ -470,6 +473,7 @@ func (s *IntegrationTestSuite) TestCLIQueryTxsCmdByEvents() {
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
true,
"",
},
}

Expand All @@ -480,7 +484,10 @@ func (s *IntegrationTestSuite) TestCLIQueryTxsCmdByEvents() {
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
s.Require().NoError(err)
if tc.expectError != "" {
s.Require().Equal(tc.expectError, err.Error())
return
}

var result sdk.SearchTxsResult
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &result))
Expand Down
6 changes: 5 additions & 1 deletion x/auth/legacy/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v043_test

import (
"fmt"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"testing"
"time"

Expand Down Expand Up @@ -663,6 +664,9 @@ func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers i
pks := simapp.CreateTestPubKeys(1)
cdc := simapp.MakeTestEncodingConfig().Marshaler

ethAddr, err := teststaking.RandomEthAddress()
require.NoError(t, err)

app.StakingKeeper = stakingkeeper.NewKeeper(
cdc,
app.GetKey(stakingtypes.StoreKey),
Expand All @@ -671,7 +675,7 @@ func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers i
app.GetSubspace(stakingtypes.ModuleName),
)

val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{}, sdk.AccAddress(pks[0].Address()), *ethAddr)
require.NoError(t, err)

app.StakingKeeper.SetValidator(ctx, val1)
Expand Down
7 changes: 5 additions & 2 deletions x/distribution/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation_test

import (
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"math/rand"
"testing"

Expand Down Expand Up @@ -245,8 +246,10 @@ func (suite *SimTestSuite) getTestingValidator(accounts []simtypes.Account, comm
account := accounts[n]
valPubKey := account.PubKey
valAddr := sdk.ValAddress(account.PubKey.Address().Bytes())
validator, err := stakingtypes.NewValidator(valAddr, valPubKey, stakingtypes.
Description{})

randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(err)
validator, err := stakingtypes.NewValidator(valAddr, valPubKey, stakingtypes.Description{}, sdk.AccAddress(valPubKey.Address()), *randomEthAddress)
require.NoError(err)
validator, err = validator.SetInitialCommission(commission)
require.NoError(err)
Expand Down
18 changes: 15 additions & 3 deletions x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o
--commission-rate=0.07 \
--details="..." \
--security-contact="..." \
--website="..."
--website="..." \
--orchestrator-address="..." \
--ethereum-address="..."
`, defaultsDesc, version.AppName,
),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -110,12 +112,22 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o
moniker = m
}

orchestratorAddress, err := cmd.Flags().GetString(flags.FlagOrchestratorAddress)
if err != nil {
return errors.Wrapf(err, "failed to get the orchestrator address")
}

ethereumAddress, err := cmd.Flags().GetString(flags.FlagEthereumAddress)
if err != nil {
return errors.Wrapf(err, "failed to get the ethereum address")
}

// set flags for creating a gentx
createValCfg, err := cli.PrepareConfigForTxCreateValidator(
cmd.Flags(), moniker,
nodeID, genDoc.ChainID,
valPubKey, cli.FlagOrchestratorAddress,
cli.FlagEthereumAddress,
valPubKey, orchestratorAddress,
ethereumAddress,
)
if err != nil {
return errors.Wrap(err, "error creating configuration to create validator msg")
Expand Down
6 changes: 6 additions & 0 deletions x/genutil/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (s *IntegrationTestSuite) TestGenTxCmd() {
fmt.Sprintf("--%s=%s", flags.FlagOutputDocument, genTxFile),
val.Moniker,
amount.String(),
fmt.Sprintf("--%s=%s", flags.FlagEthereumAddress, val.EthereumAddr.GetAddress()),
fmt.Sprintf("--%s=%s", flags.FlagOrchestratorAddress, val.OrchestratorAddr.String()),
})

err := cmd.ExecuteContext(ctx)
Expand Down Expand Up @@ -117,6 +119,8 @@ func (s *IntegrationTestSuite) TestGenTxCmdPubkey() {
fmt.Sprintf("--%s={\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey),
val.Moniker,
amount.String(),
fmt.Sprintf("--%s=%s", flags.FlagEthereumAddress, val.EthereumAddr.GetAddress()),
fmt.Sprintf("--%s=%s", flags.FlagOrchestratorAddress, val.OrchestratorAddr.String()),
})
s.Require().Error(cmd.ExecuteContext(ctx))

Expand All @@ -126,6 +130,8 @@ func (s *IntegrationTestSuite) TestGenTxCmdPubkey() {
fmt.Sprintf("--%s={\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"BOIkjkFruMpfOFC9oNPhiJGfmY2pHF/gwHdLDLnrnS0=\"}", stakingcli.FlagPubKey),
val.Moniker,
amount.String(),
fmt.Sprintf("--%s=%s", flags.FlagEthereumAddress, val.EthereumAddr.GetAddress()),
fmt.Sprintf("--%s=%s", flags.FlagOrchestratorAddress, val.OrchestratorAddr.String()),
})
s.Require().NoError(cmd.ExecuteContext(ctx))
}
19 changes: 15 additions & 4 deletions x/genutil/gentx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package genutil_test
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"testing"

"github.com/stretchr/testify/suite"
Expand All @@ -27,8 +28,12 @@ var (
pk2 = priv2.PubKey()
addr1 = sdk.AccAddress(pk1.Address())
addr2 = sdk.AccAddress(pk2.Address())
desc = stakingtypes.NewDescription("testname", "", "", "", "")
comm = stakingtypes.CommissionRates{}

ethAddr1, _ = teststaking.RandomEthAddress()
ethAddr2, _ = teststaking.RandomEthAddress()

desc = stakingtypes.NewDescription("testname", "", "", "", "")
comm = stakingtypes.CommissionRates{}
)

// GenTxTestSuite is a test suite to be used with gentx tests.
Expand All @@ -53,10 +58,16 @@ func (suite *GenTxTestSuite) SetupTest() {
amount := sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)
one := sdk.OneInt()
suite.msg1, err = stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk1.Address()), pk1, amount, desc, comm, one)
sdk.ValAddress(pk1.Address()), pk1, amount, desc, comm, one,
sdk.AccAddress(pk1.Address()),
*ethAddr1,
)
suite.NoError(err)
suite.msg2, err = stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(pk2.Address()), pk1, amount, desc, comm, one)
sdk.ValAddress(pk2.Address()), pk1, amount, desc, comm, one,
sdk.AccAddress(pk2.Address()),
*ethAddr2,
)
suite.NoError(err)
}

Expand Down
20 changes: 15 additions & 5 deletions x/genutil/types/genesis_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types_test

import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -17,8 +18,11 @@ import (
)

var (
pk1 = ed25519.GenPrivKey().PubKey()
pk2 = ed25519.GenPrivKey().PubKey()
pk1 = ed25519.GenPrivKey().PubKey()
ethAddr1, _ = teststaking.RandomEthAddress()

pk2 = ed25519.GenPrivKey().PubKey()
ethAddr2, _ = teststaking.RandomEthAddress()
)

func TestNetGenesisState(t *testing.T) {
Expand All @@ -38,11 +42,17 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
comm := stakingtypes.CommissionRates{}

msg1, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk1.Address()), pk1,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt(),
sdk.AccAddress(pk1.Address()),
*ethAddr1,
)
require.NoError(t, err)

msg2, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(pk2.Address()), pk2,
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt())
sdk.NewInt64Coin(sdk.DefaultBondDenom, 50), desc, comm, sdk.OneInt(),
sdk.AccAddress(pk2.Address()),
*ethAddr2,
)
require.NoError(t, err)

txGen := simapp.MakeTestEncodingConfig().TxConfig
Expand All @@ -59,7 +69,7 @@ func TestValidateGenesisMultipleMessages(t *testing.T) {
func TestValidateGenesisBadMessage(t *testing.T) {
desc := stakingtypes.NewDescription("testname", "", "", "", "")

msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()), desc, nil, nil)
msg1 := stakingtypes.NewMsgEditValidator(sdk.ValAddress(pk1.Address()), desc, nil, nil, nil, nil)

txGen := simapp.MakeTestEncodingConfig().TxConfig
txBuilder := txGen.NewTxBuilder()
Expand Down
Loading