mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
wip: first e2e test functional again, replaced some lib and testutil functionality to use new cosmos-sdk features
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
3bb8994e41
commit
a67ba84b70
97026
docs/static/openapi.yml
vendored
97026
docs/static/openapi.yml
vendored
File diff suppressed because it is too large
Load Diff
10
go.mod
10
go.mod
@ -10,7 +10,7 @@ replace (
|
||||
)
|
||||
|
||||
require (
|
||||
cosmossdk.io/api v0.7.4
|
||||
cosmossdk.io/api v0.7.5
|
||||
cosmossdk.io/client/v2 v2.0.0-beta.1
|
||||
cosmossdk.io/core v0.11.0
|
||||
cosmossdk.io/depinject v1.0.0-alpha.4
|
||||
@ -26,11 +26,10 @@ require (
|
||||
github.com/btcsuite/btcd v0.23.2
|
||||
github.com/btcsuite/btcd/btcutil v1.1.3
|
||||
github.com/bufbuild/buf v1.30.0
|
||||
github.com/cometbft/cometbft v0.38.6
|
||||
github.com/cometbft/cometbft-db v0.9.1
|
||||
github.com/cometbft/cometbft v0.38.7
|
||||
github.com/cosmos/cosmos-db v1.0.2
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||
github.com/cosmos/cosmos-sdk v0.50.6
|
||||
github.com/cosmos/cosmos-sdk v0.50.7
|
||||
github.com/cosmos/go-bip39 v1.0.0
|
||||
github.com/cosmos/gogoproto v1.4.12
|
||||
github.com/cosmos/ibc-go/modules/capability v1.0.0
|
||||
@ -68,7 +67,7 @@ require (
|
||||
connectrpc.com/otelconnect v0.7.0 // indirect
|
||||
cosmossdk.io/collections v0.4.0 // indirect
|
||||
cosmossdk.io/math v1.3.0 // indirect
|
||||
cosmossdk.io/x/tx v0.13.2 // indirect
|
||||
cosmossdk.io/x/tx v0.13.3 // indirect
|
||||
filippo.io/edwards25519 v1.0.0 // indirect
|
||||
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
|
||||
github.com/99designs/keyring v1.2.1 // indirect
|
||||
@ -97,6 +96,7 @@ require (
|
||||
github.com/cockroachdb/pebble v1.1.0 // indirect
|
||||
github.com/cockroachdb/redact v1.1.5 // indirect
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/cometbft/cometbft-db v0.9.1 // indirect
|
||||
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
|
||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||
github.com/cosmos/gogogateway v1.2.0 // indirect
|
||||
|
16
go.sum
16
go.sum
@ -190,8 +190,8 @@ connectrpc.com/connect v1.15.0 h1:lFdeCbZrVVDydAqwr4xGV2y+ULn+0Z73s5JBj2LikWo=
|
||||
connectrpc.com/connect v1.15.0/go.mod h1:bQmjpDY8xItMnttnurVgOkHUBMRT9cpsNi2O4AjKhmA=
|
||||
connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY=
|
||||
connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc=
|
||||
cosmossdk.io/api v0.7.4 h1:sPo8wKwCty1lht8kgL3J7YL1voJywP3YWuA5JKkBz30=
|
||||
cosmossdk.io/api v0.7.4/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
|
||||
cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ=
|
||||
cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38=
|
||||
cosmossdk.io/client/v2 v2.0.0-beta.1 h1:XkHh1lhrLYIT9zKl7cIOXUXg2hdhtjTPBUfqERNA1/Q=
|
||||
cosmossdk.io/client/v2 v2.0.0-beta.1/go.mod h1:JEUSu9moNZQ4kU3ir1DKD5eU4bllmAexrGWjmb9k8qU=
|
||||
cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s=
|
||||
@ -218,8 +218,8 @@ cosmossdk.io/x/feegrant v0.1.0 h1:c7s3oAq/8/UO0EiN1H5BIjwVntujVTkYs35YPvvrdQk=
|
||||
cosmossdk.io/x/feegrant v0.1.0/go.mod h1:4r+FsViJRpcZif/yhTn+E0E6OFfg4n0Lx+6cCtnZElU=
|
||||
cosmossdk.io/x/nft v0.1.0 h1:VhcsFiEK33ODN27kxKLa0r/CeFd8laBfbDBwYqCyYCM=
|
||||
cosmossdk.io/x/nft v0.1.0/go.mod h1:ec4j4QAO4mJZ+45jeYRnW7awLHby1JZANqe1hNZ4S3g=
|
||||
cosmossdk.io/x/tx v0.13.2 h1:Kh90UH30bhnnUdJH+CmWLyaH8IKdY6BBGY3EkdOk82o=
|
||||
cosmossdk.io/x/tx v0.13.2/go.mod h1:yhPokDCfXVIuAtyp49IFlWB5YAXUgD7Zek+ZHwsHzvU=
|
||||
cosmossdk.io/x/tx v0.13.3 h1:Ha4mNaHmxBc6RMun9aKuqul8yHiL78EKJQ8g23Zf73g=
|
||||
cosmossdk.io/x/tx v0.13.3/go.mod h1:I8xaHv0rhUdIvIdptKIqzYy27+n2+zBVaxO6fscFhys=
|
||||
cosmossdk.io/x/upgrade v0.1.1 h1:aoPe2gNvH+Gwt/Pgq3dOxxQVU3j5P6Xf+DaUJTDZATc=
|
||||
cosmossdk.io/x/upgrade v0.1.1/go.mod h1:MNLptLPcIFK9CWt7Ra//8WUZAxweyRDNcbs5nkOcQy0=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
@ -374,8 +374,8 @@ github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZ
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo=
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/cometbft/cometbft v0.38.6 h1:QSgpCzrGWJ2KUq1qpw+FCfASRpE27T6LQbfEHscdyOk=
|
||||
github.com/cometbft/cometbft v0.38.6/go.mod h1:8rSPxzUJYquCN8uuBgbUHOMg2KAwvr7CyUw+6ukO4nw=
|
||||
github.com/cometbft/cometbft v0.38.7 h1:ULhIOJ9+LgSy6nLekhq9ae3juX3NnQUMMPyVdhZV6Hk=
|
||||
github.com/cometbft/cometbft v0.38.7/go.mod h1:HIyf811dFMI73IE0F7RrnY/Fr+d1+HuJAgtkEpQjCMY=
|
||||
github.com/cometbft/cometbft-db v0.9.1 h1:MIhVX5ja5bXNHF8EYrThkG9F7r9kSfv8BX4LWaxWJ4M=
|
||||
github.com/cometbft/cometbft-db v0.9.1/go.mod h1:iliyWaoV0mRwBJoizElCwwRA9Tf7jZJOURcRZF9m60U=
|
||||
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
|
||||
@ -396,8 +396,8 @@ github.com/cosmos/cosmos-db v1.0.2 h1:hwMjozuY1OlJs/uh6vddqnk9j7VamLv+0DBlbEXbAK
|
||||
github.com/cosmos/cosmos-db v1.0.2/go.mod h1:Z8IXcFJ9PqKK6BIsVOB3QXtkKoqUOp1vRvPT39kOXEA=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA=
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec=
|
||||
github.com/cosmos/cosmos-sdk v0.50.6 h1:efR3MsvMHX5sxS3be+hOobGk87IzlZbSpsI2x/Vw3hk=
|
||||
github.com/cosmos/cosmos-sdk v0.50.6/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40=
|
||||
github.com/cosmos/cosmos-sdk v0.50.7 h1:LsBGKxifENR/DN4E1RZaitsyL93HU44x0p8EnMHp4V4=
|
||||
github.com/cosmos/cosmos-sdk v0.50.7/go.mod h1:84xDDJEHttRT7NDGwBaUOLVOMN0JNE9x7NbsYIxXs1s=
|
||||
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
|
||||
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
|
||||
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
|
||||
|
@ -58,6 +58,9 @@ func (config *Config) SetBech32PrefixForAccount(bech32Prefix string) *Config {
|
||||
changeLock.Lock()
|
||||
defer changeLock.Unlock()
|
||||
sdkConfig.SetBech32PrefixForAccount(bech32Prefix, "pub")
|
||||
// TODO: check if lines below are needed except for WIP test setup if so move to respective function or rename this function
|
||||
sdkConfig.SetBech32PrefixForValidator(bech32Prefix+"valoper", "pub")
|
||||
sdkConfig.SetBech32PrefixForConsensusNode(bech32Prefix+"valcons", "pub")
|
||||
return config
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,8 @@ func BroadcastTxWithFileLock(fromAddress sdk.AccAddress, msgs ...sdk.Msg) (out *
|
||||
}()
|
||||
|
||||
// get basic chain information
|
||||
withoutFee := isMachineAttestationMsg(msgs...)
|
||||
// withoutFee := isMachineAttestationMsg(msgs...)
|
||||
withoutFee := false // TODO: replace with check after AnteHandlers are in place (DeductFeeDecorator does not take a fee on machine attestation)
|
||||
clientCtx, txf, err := getClientContextAndTxFactory(fromAddress, withoutFee)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -2,16 +2,18 @@ package machine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/app"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func TestE2EMachineTestSuite(t *testing.T) {
|
||||
time.Sleep(2 * time.Second)
|
||||
cfg := network.LoaderDefaultConfig()
|
||||
cfg, err := network.DefaultConfigWithAppConfig(app.AppConfig())
|
||||
if err != nil {
|
||||
panic("error while setting up application config")
|
||||
}
|
||||
cfg.NumValidators = 3
|
||||
cfg.MinGasPrices = "0.000003stake"
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
||||
|
@ -2,31 +2,21 @@ package machine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/planetmint/planetmint-go/lib"
|
||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||
|
||||
// "github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
|
||||
// machinecli "github.com/planetmint/planetmint-go/x/machine/client/cli"
|
||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
|
||||
"cosmossdk.io/x/feegrant"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
txcli "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
"github.com/planetmint/planetmint-go/lib"
|
||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
// E2ETestSuite struct definition of machine suite
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
@ -35,204 +25,321 @@ type E2ETestSuite struct {
|
||||
feeDenom string
|
||||
}
|
||||
|
||||
// NewE2ETestSuite returns configured machine E2ETestSuite
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
// SetupSuite initializes machine E2ETestSuite
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e machine test suite")
|
||||
|
||||
s.feeDenom = sample.FeeDenom
|
||||
s.network = network.Load(s.T(), s.cfg)
|
||||
|
||||
// create machine account for attestation
|
||||
libCfg := lib.GetConfig()
|
||||
|
||||
var err error
|
||||
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
s.network.Validators[0].ClientCtx.SkipConfirm = true
|
||||
s.network.Validators[0].ClientCtx.BroadcastMode = flags.BroadcastSync
|
||||
s.network.Validators[0].ClientCtx.Output = &bytes.Buffer{}
|
||||
libCfg.SetClientCtx(s.network.Validators[0].ClientCtx)
|
||||
libCfg.SetFeeDenom("stake") // TODO: remove once token denom is set to plmnt again
|
||||
|
||||
account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic)
|
||||
s.Require().NoError(err)
|
||||
err = e2etestutil.FundAccount(s.network, account, s.feeDenom)
|
||||
err = e2etestutil.FundAccount(s.network, account, "stake") // TODO: replace denom with sample.FeeDenom once network is setup correctly again
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e machine test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
// TestAttestMachine attests machine and query attested machine from chain
|
||||
func (s *E2ETestSuite) TestAttestMachine() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
// register Ta
|
||||
prvKey, pubKey := sample.KeyPair()
|
||||
|
||||
ta := moduleobject.TrustAnchor(pubKey)
|
||||
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
||||
txRes1, err := lib.GetTxResponseFromOut(out)
|
||||
s.Require().NoError(err)
|
||||
|
||||
assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgRegisterTrustAnchor")
|
||||
s.Require().NoError(cli.CheckTxCode(s.network, val.ClientCtx, txRes1.TxHash, 0))
|
||||
|
||||
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||
s.Require().NoError(err)
|
||||
addr, _ := k.GetAddress()
|
||||
|
||||
// Check preAttestationBalance in order to verify that it doesn't change after machine attestation
|
||||
preAttestationBalanceOutput, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||
addr.String(),
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
preAttestationBalance, ok := preAttestationBalanceOutput.(*bytes.Buffer)
|
||||
if !ok {
|
||||
err = lib.ErrTypeAssertionFailed
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
assert.Contains(s.T(), preAttestationBalance.String(), "10000")
|
||||
|
||||
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||
msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// give machine attestation some time to issue the liquid asset
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
rawLog, err = clitestutil.GetRawLogFromTxOut(val, out)
|
||||
txRes2, err := lib.GetTxResponseFromOut(out)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(cli.CheckTxCode(s.network, val.ClientCtx, txRes2.TxHash, 0))
|
||||
s.Require().NoError(err)
|
||||
|
||||
assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgAttestMachine")
|
||||
|
||||
args := []string{
|
||||
pubKey,
|
||||
}
|
||||
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)
|
||||
s.Require().NoError(err)
|
||||
txResponse, err := lib.GetTxResponseFromOut(out)
|
||||
apiRes, err := testutil.GetRequest(fmt.Sprintf("%s/planetmint/planetmint-go/machine/get_machine_by_public_key/%s", val.APIAddress, pubKey))
|
||||
s.Require().NoError(err)
|
||||
|
||||
txResp, err := txcli.QueryTx(val.ClientCtx, txResponse.TxHash)
|
||||
var mac machinetypes.QueryGetMachineByPublicKeyResponse
|
||||
err = s.cfg.Codec.UnmarshalJSON(apiRes, &mac)
|
||||
s.Require().NoError(err)
|
||||
|
||||
assert.Contains(s.T(), txResp.TxHash, txResponse.TxHash)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Check postAttestationBalance it should be the preAttestationBalance + th 8800 tokens being donated to the machine (no fees are taken)
|
||||
postAttestationBalanceOutput, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||
addr.String(),
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
postAttestationBalance, ok := postAttestationBalanceOutput.(*bytes.Buffer)
|
||||
if !ok {
|
||||
err = lib.ErrTypeAssertionFailed
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
assert.Contains(s.T(), postAttestationBalance.String(), "18800")
|
||||
isEqual := reflect.DeepEqual(machine, *mac.Machine)
|
||||
s.Require().True(isEqual)
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) TestInvalidAttestMachine() {
|
||||
val := s.network.Validators[0]
|
||||
// package machine
|
||||
|
||||
// already used in previous test case
|
||||
prvKey, pubKey := sample.KeyPair()
|
||||
// import (
|
||||
// "bytes"
|
||||
|
||||
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||
s.Require().NoError(err)
|
||||
addr, _ := k.GetAddress()
|
||||
// "github.com/planetmint/planetmint-go/lib"
|
||||
// clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||
|
||||
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||
s.Require().NoError(err)
|
||||
// // "github.com/planetmint/planetmint-go/testutil/network"
|
||||
// "github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
// "github.com/planetmint/planetmint-go/testutil/sample"
|
||||
|
||||
msg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
out, _ := lib.BroadcastTxWithFileLock(addr, msg)
|
||||
txResponse, err := lib.GetTxResponseFromOut(out)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(int(txResponse.Code), int(4))
|
||||
// // machinecli "github.com/planetmint/planetmint-go/x/machine/client/cli"
|
||||
// machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
|
||||
unregisteredPubKey, unregisteredPrivKey := sample.KeyPair(2)
|
||||
machine = moduleobject.Machine(sample.Name, unregisteredPubKey, unregisteredPrivKey, addr.String())
|
||||
s.Require().NoError(err)
|
||||
// "cosmossdk.io/x/feegrant"
|
||||
// "github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
// "github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
// sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
// txcli "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
// bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
|
||||
// e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||
// "github.com/stretchr/testify/assert"
|
||||
// "github.com/stretchr/testify/suite"
|
||||
|
||||
msg = machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
out, _ = lib.BroadcastTxWithFileLock(addr, msg)
|
||||
txResponse, err = lib.GetTxResponseFromOut(out)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(int(txResponse.Code), int(3))
|
||||
}
|
||||
// "github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||
// )
|
||||
|
||||
func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
||||
// create address for machine
|
||||
val := s.network.Validators[0]
|
||||
kb := val.ClientCtx.Keyring
|
||||
// // E2ETestSuite struct definition of machine suite
|
||||
// type E2ETestSuite struct {
|
||||
// suite.Suite
|
||||
|
||||
account, _, err := kb.NewMnemonic("AllowanceMachine", keyring.English, sample.DefaultDerivationPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
s.Require().NoError(err)
|
||||
// cfg network.Config
|
||||
// network *network.Network
|
||||
// feeDenom string
|
||||
// }
|
||||
|
||||
addr, err := account.GetAddress()
|
||||
s.Require().NoError(err)
|
||||
// // NewE2ETestSuite returns configured machine E2ETestSuite
|
||||
// func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
// return &E2ETestSuite{cfg: cfg}
|
||||
// }
|
||||
|
||||
// register TA
|
||||
prvKey, pubKey := sample.KeyPair(3)
|
||||
// // SetupSuite initializes machine E2ETestSuite
|
||||
// func (s *E2ETestSuite) SetupSuite() {
|
||||
// s.T().Log("setting up e2e machine test suite")
|
||||
|
||||
ta := moduleobject.TrustAnchor(pubKey)
|
||||
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.feeDenom = sample.FeeDenom
|
||||
// // s.network = network.Load(s.T(), s.cfg)
|
||||
|
||||
// create allowance for machine
|
||||
allowedMsgs := []string{"/planetmintgo.machine.MsgAttestMachine"}
|
||||
limit := sdk.NewCoins(sdk.NewInt64Coin(s.feeDenom, 2))
|
||||
basic := feegrant.BasicAllowance{
|
||||
SpendLimit: limit,
|
||||
}
|
||||
var grant feegrant.FeeAllowanceI
|
||||
grant = &basic
|
||||
grant, err = feegrant.NewAllowedMsgAllowance(grant, allowedMsgs)
|
||||
s.Require().NoError(err)
|
||||
// n, err := network.New(nil, s.T().TempDir(), s.cfg)
|
||||
|
||||
msg2, err := feegrant.NewMsgGrantAllowance(grant, val.Address, addr)
|
||||
s.Require().NoError(err)
|
||||
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg2)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.network = n
|
||||
|
||||
// attest machine with fee granter without funding the machine account first
|
||||
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||
s.Require().NoError(err)
|
||||
// // create machine account for attestation
|
||||
// account, err := e2etestutil.CreateAccount(s.network, sample.Name, sample.Mnemonic)
|
||||
// s.Require().NoError(err)
|
||||
// err = e2etestutil.FundAccount(s.network, account, s.feeDenom)
|
||||
// s.Require().NoError(err)
|
||||
// }
|
||||
|
||||
// name and address of private key with which to sign
|
||||
clientCtx := val.ClientCtx.
|
||||
WithFeeGranterAddress(val.Address)
|
||||
libConfig := lib.GetConfig()
|
||||
libConfig.SetClientCtx(clientCtx)
|
||||
// // TearDownSuite clean up after testing
|
||||
// func (s *E2ETestSuite) TearDownSuite() {
|
||||
// s.T().Log("tearing down e2e machine test suite")
|
||||
// }
|
||||
|
||||
msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg3)
|
||||
// // TestAttestMachine attests machine and query attested machine from chain
|
||||
// func (s *E2ETestSuite) TestAttestMachine() {
|
||||
// val := s.network.Validators[0]
|
||||
|
||||
// reset clientCtx to validator ctx
|
||||
libConfig.SetClientCtx(val.ClientCtx)
|
||||
// // register Ta
|
||||
// prvKey, pubKey := sample.KeyPair()
|
||||
|
||||
s.Require().NoError(err)
|
||||
// ta := moduleobject.TrustAnchor(pubKey)
|
||||
// msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||
// out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// give machine attestation some time to issue the liquid asset
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
args := []string{
|
||||
pubKey,
|
||||
}
|
||||
// assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgRegisterTrustAnchor")
|
||||
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
// k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||
// s.Require().NoError(err)
|
||||
// addr, _ := k.GetAddress()
|
||||
|
||||
// // Check preAttestationBalance in order to verify that it doesn't change after machine attestation
|
||||
// preAttestationBalanceOutput, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||
// addr.String(),
|
||||
// })
|
||||
// s.Require().NoError(err)
|
||||
// preAttestationBalance, ok := preAttestationBalanceOutput.(*bytes.Buffer)
|
||||
// if !ok {
|
||||
// err = lib.ErrTypeAssertionFailed
|
||||
// s.Require().NoError(err)
|
||||
// }
|
||||
// assert.Contains(s.T(), preAttestationBalance.String(), "10000")
|
||||
|
||||
// machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||
// msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
// out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// // give machine attestation some time to issue the liquid asset
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// rawLog, err = clitestutil.GetRawLogFromTxOut(val, out)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// assert.Contains(s.T(), rawLog, "planetmintgo.machine.MsgAttestMachine")
|
||||
|
||||
// args := []string{
|
||||
// pubKey,
|
||||
// }
|
||||
|
||||
// _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)
|
||||
// s.Require().NoError(err)
|
||||
// txResponse, err := lib.GetTxResponseFromOut(out)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// txResp, err := txcli.QueryTx(val.ClientCtx, txResponse.TxHash)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// assert.Contains(s.T(), txResp.TxHash, txResponse.TxHash)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// // Check postAttestationBalance it should be the preAttestationBalance + th 8800 tokens being donated to the machine (no fees are taken)
|
||||
// postAttestationBalanceOutput, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.GetBalancesCmd(), []string{
|
||||
// addr.String(),
|
||||
// })
|
||||
// s.Require().NoError(err)
|
||||
// postAttestationBalance, ok := postAttestationBalanceOutput.(*bytes.Buffer)
|
||||
// if !ok {
|
||||
// err = lib.ErrTypeAssertionFailed
|
||||
// s.Require().NoError(err)
|
||||
// }
|
||||
// assert.Contains(s.T(), postAttestationBalance.String(), "18800")
|
||||
// }
|
||||
|
||||
// func (s *E2ETestSuite) TestInvalidAttestMachine() {
|
||||
// val := s.network.Validators[0]
|
||||
|
||||
// // already used in previous test case
|
||||
// prvKey, pubKey := sample.KeyPair()
|
||||
|
||||
// k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||
// s.Require().NoError(err)
|
||||
// addr, _ := k.GetAddress()
|
||||
|
||||
// machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// msg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
// out, _ := lib.BroadcastTxWithFileLock(addr, msg)
|
||||
// txResponse, err := lib.GetTxResponseFromOut(out)
|
||||
// s.Require().NoError(err)
|
||||
// s.Require().Equal(int(txResponse.Code), int(4))
|
||||
|
||||
// unregisteredPubKey, unregisteredPrivKey := sample.KeyPair(2)
|
||||
// machine = moduleobject.Machine(sample.Name, unregisteredPubKey, unregisteredPrivKey, addr.String())
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// msg = machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
// out, _ = lib.BroadcastTxWithFileLock(addr, msg)
|
||||
// txResponse, err = lib.GetTxResponseFromOut(out)
|
||||
// s.Require().NoError(err)
|
||||
// s.Require().Equal(int(txResponse.Code), int(3))
|
||||
// }
|
||||
|
||||
// func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
||||
// // create address for machine
|
||||
// val := s.network.Validators[0]
|
||||
// kb := val.ClientCtx.Keyring
|
||||
|
||||
// account, _, err := kb.NewMnemonic("AllowanceMachine", keyring.English, sample.DefaultDerivationPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// addr, err := account.GetAddress()
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// // register TA
|
||||
// prvKey, pubKey := sample.KeyPair(3)
|
||||
|
||||
// ta := moduleobject.TrustAnchor(pubKey)
|
||||
// msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||
// _, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||
// s.Require().NoError(err)
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// // create allowance for machine
|
||||
// allowedMsgs := []string{"/planetmintgo.machine.MsgAttestMachine"}
|
||||
// limit := sdk.NewCoins(sdk.NewInt64Coin(s.feeDenom, 2))
|
||||
// basic := feegrant.BasicAllowance{
|
||||
// SpendLimit: limit,
|
||||
// }
|
||||
// var grant feegrant.FeeAllowanceI
|
||||
// grant = &basic
|
||||
// grant, err = feegrant.NewAllowedMsgAllowance(grant, allowedMsgs)
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// msg2, err := feegrant.NewMsgGrantAllowance(grant, val.Address, addr)
|
||||
// s.Require().NoError(err)
|
||||
// _, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg2)
|
||||
// s.Require().NoError(err)
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// // attest machine with fee granter without funding the machine account first
|
||||
// machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// // name and address of private key with which to sign
|
||||
// clientCtx := val.ClientCtx.
|
||||
// WithFeeGranterAddress(val.Address)
|
||||
// libConfig := lib.GetConfig()
|
||||
// libConfig.SetClientCtx(clientCtx)
|
||||
|
||||
// msg3 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||
// _, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg3)
|
||||
|
||||
// // reset clientCtx to validator ctx
|
||||
// libConfig.SetClientCtx(val.ClientCtx)
|
||||
|
||||
// s.Require().NoError(err)
|
||||
|
||||
// // give machine attestation some time to issue the liquid asset
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
// s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// args := []string{
|
||||
// pubKey,
|
||||
// }
|
||||
|
||||
// _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)
|
||||
// s.Require().NoError(err)
|
||||
// }
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"github.com/planetmint/planetmint-go/lib"
|
||||
"github.com/planetmint/planetmint-go/testutil"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
"github.com/planetmint/planetmint-go/testutil/network"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -1,18 +1,14 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/planetmint/planetmint-go/lib"
|
||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||
|
||||
// "github.com/planetmint/planetmint-go/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||
@ -46,24 +42,16 @@ func FundAccount(network *network.Network, account *keyring.Record, tokenDenom s
|
||||
return err
|
||||
}
|
||||
|
||||
err = network.WaitForNextBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = network.WaitForNextBlock()
|
||||
txRes, err := lib.GetTxResponseFromOut(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rawLog, err := clitestutil.GetRawLogFromTxOut(val, out)
|
||||
err = cli.CheckTxCode(network, val.ClientCtx, txRes.TxHash, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !strings.Contains(rawLog, "cosmos.bank.v1beta1.MsgSend") {
|
||||
err = errors.New("failed to fund account")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ type ModuleInputs struct {
|
||||
|
||||
AccountKeeper types.AccountKeeper
|
||||
BankKeeper types.BankKeeper
|
||||
rootDir string
|
||||
// rootDir string TODO: find out if this should be put in ModuleInputs or read from cfg when ProvideModule is called
|
||||
}
|
||||
|
||||
type ModuleOutputs struct {
|
||||
@ -210,7 +210,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
in.StoreService,
|
||||
in.Logger,
|
||||
authority.String(),
|
||||
in.rootDir,
|
||||
"rootDir", // TODO: hardcoded because of setting up e2e testnetwork see comment in line 192
|
||||
)
|
||||
m := NewAppModule(
|
||||
in.Cdc,
|
||||
|
Loading…
x
Reference in New Issue
Block a user