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

[Testing, Tooling] feat: implement in-memory networks #290

Closed
wants to merge 94 commits into from
Closed
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
4bcd8de
refactor: `NewMinedRelay` to shared testutil
bryanchriswhite Dec 12, 2023
673911c
refactor: claim & proof protobuf types
bryanchriswhite Dec 12, 2023
fd55896
refactor: rename supplier keeper `UpsertClaim` & `UpsertProof`
bryanchriswhite Dec 7, 2023
43cbf0e
refactor: misc. claim-side improvements
bryanchriswhite Dec 12, 2023
ef3cd99
chore: add TODOs
bryanchriswhite Dec 13, 2023
f509fbf
refactor: supplier module keys
bryanchriswhite Dec 12, 2023
6817364
refactor: supplier module errors
bryanchriswhite Dec 12, 2023
6e60952
chore: review feedback improvements
bryanchriswhite Dec 22, 2023
edc4e41
chore: review feedback improvements
bryanchriswhite Dec 22, 2023
7994ca2
Merge remote-tracking branch 'pokt/main' into issues/141/refactor/cla…
bryanchriswhite Dec 22, 2023
6a5b3e6
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Dec 22, 2023
dfb067d
chore: review feedback improvements
bryanchriswhite Dec 22, 2023
0351cc7
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Dec 22, 2023
b82e49a
fix: pre-generated keyring accounts
bryanchriswhite Dec 19, 2023
2d52838
fix: session hydrator
bryanchriswhite Dec 21, 2023
6a9d6ec
feat: add InMemoryCosmosNetwork interface
bryanchriswhite Dec 21, 2023
5566e5c
chore: add InMemoryNetworkConfig
bryanchriswhite Dec 21, 2023
923907b
chore: add TODO comment
bryanchriswhite Dec 21, 2023
8b57b22
Revert "fix: pre-generated keyring accounts"
bryanchriswhite Dec 21, 2023
eee5dcf
chore: add BaseInMemoryCosmosNetwork abstract impl.
bryanchriswhite Dec 21, 2023
4af4132
feat: add inMemoryNetworkWithSessions impl.
bryanchriswhite Dec 21, 2023
ae7de37
feat: add inMemoryNetworkWithGateways
bryanchriswhite Dec 21, 2023
a2e53c1
chore: add GetGenesis test helper
bryanchriswhite Dec 21, 2023
93125b0
chore: add godoc comments & simplify
bryanchriswhite Dec 22, 2023
6737cb7
fixup! feat: add inMemoryNetworkWithSessions impl.
bryanchriswhite Dec 22, 2023
35cd36a
chore: self-review
bryanchriswhite Dec 22, 2023
41ee458
Merge branch 'issues/141/prep/in-memory-network' into issues/141/feat…
bryanchriswhite Dec 22, 2023
86f281d
fix: linter errors
bryanchriswhite Jan 2, 2024
d3a21e3
chore: self-review improvements
bryanchriswhite Jan 2, 2024
1fbf000
fixup! fix: linter errors
bryanchriswhite Jan 2, 2024
b11bbe3
chore: add TODOs
bryanchriswhite Jan 8, 2024
f3e7866
Merge remote-tracking branch 'pokt/main' into issues/141/refactor/cla…
bryanchriswhite Jan 8, 2024
df9e3c2
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Jan 8, 2024
bca059c
trigger CI
bryanchriswhite Jan 8, 2024
8ab13f0
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Jan 8, 2024
c21071b
chore: review feedback improvements
bryanchriswhite Jan 8, 2024
6515c64
chore: update comment
bryanchriswhite Jan 8, 2024
b4ed47c
Merge branch 'issues/141/refactor/supplier-errors' into issues/141/pr…
bryanchriswhite Jan 8, 2024
7987e14
chore: rename InMemoryCosmosNetwork to InMemoryNetwork
bryanchriswhite Jan 8, 2024
cdcfb7d
chore: add #GetConfig()
bryanchriswhite Jan 8, 2024
191c956
Merge branch 'issues/141/prep/in-memory-network' into issues/141/feat…
bryanchriswhite Jan 8, 2024
92c0a19
chore: fix comment
bryanchriswhite Jan 8, 2024
0a6b950
Merge branch 'issues/141/prep/in-memory-network' into issues/141/feat…
bryanchriswhite Jan 8, 2024
86548cd
chore: post-merge refactor
bryanchriswhite Jan 8, 2024
ff09a42
chore: fix comment typo
bryanchriswhite Jan 8, 2024
8e84c43
Merge branch 'issues/141/prep/in-memory-network' into issues/141/feat…
bryanchriswhite Jan 8, 2024
9f472f6
trigger CI
bryanchriswhite Jan 8, 2024
3de1971
chore: add TODO
bryanchriswhite Jan 9, 2024
800b53b
Merge remote-tracking branch 'pokt/main' into issues/141/refactor/cla…
bryanchriswhite Jan 9, 2024
8e0f4e9
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Jan 9, 2024
2b32545
chore: generalize ErrSupplierInvalidAddress and simplify
bryanchriswhite Dec 13, 2023
f41547e
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Jan 9, 2024
a527f23
Merge branch 'issues/141/refactor/supplier-errors' into issues/141/pr…
bryanchriswhite Jan 9, 2024
27b662c
Merge branch 'issues/141/prep/in-memory-network' into issues/141/feat…
bryanchriswhite Jan 9, 2024
03bb983
rename: BaseInMemoryNetwork#CreateOnChainAccounts to #FundOnChainAcco…
bryanchriswhite Jan 9, 2024
a9c2a78
refactor: rename & simplify
bryanchriswhite Jan 9, 2024
a92ad13
chore: review feedback improvements
bryanchriswhite Jan 9, 2024
5905d20
Merge branch 'main' into issues/141/refactor/claim-proof
bryanchriswhite Jan 10, 2024
4248b0b
chore: review feedback improvements
bryanchriswhite Jan 10, 2024
f064432
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Jan 10, 2024
7bacad9
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Jan 10, 2024
6d5826f
fix: usage raw string literal
bryanchriswhite Jan 10, 2024
92970b9
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Jan 10, 2024
ab3fd1e
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Jan 10, 2024
a57273c
chore: review feedback improvements
bryanchriswhite Jan 10, 2024
8486a8c
Merge branch 'issues/141/refactor/supplier-errors' into issues/141/pr…
bryanchriswhite Jan 10, 2024
53faaac
Merge branch 'main' into issues/141/refactor/claim-proof
bryanchriswhite Jan 10, 2024
0ada011
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Jan 10, 2024
6df8994
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Jan 10, 2024
2f1232c
chore: review feedback improvements
bryanchriswhite Jan 10, 2024
bd60220
Merge branch 'issues/141/refactor/supplier-errors' into issues/141/pr…
bryanchriswhite Jan 10, 2024
c648d4f
Merge remote-tracking branch 'pokt/main' into issues/141/refactor/cla…
bryanchriswhite Jan 10, 2024
dd53efc
Merge branch 'issues/141/refactor/claim-proof' into issues/141/refact…
bryanchriswhite Jan 10, 2024
fea3d27
Merge remote-tracking branch 'pokt/main' into issues/141/refactor/sup…
bryanchriswhite Jan 10, 2024
c00e1b2
Merge branch 'issues/141/refactor/supplier-keys' into issues/141/refa…
bryanchriswhite Jan 10, 2024
7d1b1e0
Merge remote-tracking branch 'pokt/main' into issues/141/refactor/sup…
bryanchriswhite Jan 10, 2024
dd5ea83
Merge branch 'issues/141/refactor/supplier-errors' into issues/141/pr…
bryanchriswhite Jan 10, 2024
afbefe7
trigger CI
bryanchriswhite Jan 10, 2024
24afe56
chore: review feedback improvements
bryanchriswhite Jan 10, 2024
fe5e743
chore: review feedback improvements
bryanchriswhite Jan 10, 2024
6c35227
Merge remote-tracking branch 'pokt/main' into issues/141/prep/in-memo…
bryanchriswhite Jan 10, 2024
b0b0436
Merge branch 'issues/141/prep/in-memory-network' into issues/141/feat…
bryanchriswhite Jan 10, 2024
dc07730
fixup! chore: review feedback improvements
bryanchriswhite Jan 10, 2024
a906d45
fix: linter errors
bryanchriswhite Jan 10, 2024
cd19c7e
Merge branch 'main' into issues/141/feat/in-memory-network
bryanchriswhite Jan 11, 2024
12dbc57
chore: review feedback improvements
bryanchriswhite Jan 12, 2024
c1774bf
chore: review feedback improvements
bryanchriswhite Jan 22, 2024
985a817
chore: review feedback improvements
bryanchriswhite Jan 22, 2024
e905b12
chore: review feedback improvements
bryanchriswhite Jan 22, 2024
413f80e
ch
bryanchriswhite Jan 22, 2024
911c423
Merge branch 'main' into issues/141/feat/in-memory-network
bryanchriswhite Jan 22, 2024
3f03074
chore: review feedback improvements
bryanchriswhite Jan 22, 2024
4516ff5
chore: review feedback improvements
bryanchriswhite Jan 22, 2024
86c7133
fix: linter errors
bryanchriswhite Jan 22, 2024
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
199 changes: 199 additions & 0 deletions testutil/network/basenet/accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package basenet

import (
"encoding/json"
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
testcli "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/network"
"github.com/pokt-network/poktroll/testutil/testkeyring"
apptypes "github.com/pokt-network/poktroll/x/application/types"
gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
)

const warnNoModuleGenesisFmt = "WARN: no %s module genesis state found, if this is unexpected, ensure that genesis is populated before creating on-chain accounts"

// CreateKeyringAccounts populates the Keyring associated with the in-memory
// network with memnet.numKeyringAccounts() number of pre-generated accounts.
func (memnet *BaseInMemoryNetwork) CreateKeyringAccounts(t *testing.T) {
t.Helper()

// Keyring MAY be provided setting InMemoryNetworkConfig#Keyring.
if memnet.Config.Keyring == nil {
t.Log("Keyring not initialized, using new in-memory keyring")

// Construct an in-memory keyring so that it can be populated and used prior
// to network start.
memnet.Config.Keyring = keyring.NewInMemory(memnet.Config.CosmosCfg.Codec)
} else {
t.Log("Keyring already initialized, using existing keyring")
}

// Create memnet.NumKeyringAccounts() number of accounts in the configured keyring.
accts := testkeyring.CreatePreGeneratedKeyringAccounts(
t, memnet.Config.Keyring, memnet.Config.GetNumKeyringAccounts(t),
)

// Assign the memnet's pre-generated accounts iterator to a new pre-generated
// accounts iterator containing only the accounts which were also created
// in the keyring.
memnet.PreGeneratedAccountIterator = testkeyring.NewPreGeneratedAccountIterator(accts...)
}

// FundOnChainAccounts creates on-chain accounts (i.e. auth module) for the sum of
// the configured number of suppliers, applications, and gateways.
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
func (memnet *BaseInMemoryNetwork) FundOnChainAccounts(t *testing.T) {
t.Helper()

// NB: while it may initially seem like the memnet#Fund<actor>Accounts() methods
h5law marked this conversation as resolved.
Show resolved Hide resolved
// can be refactored into a generic function, this is not possible so long as the genesis
// state lists are passed directly & remain a slice of concrete types (as opposed to pointers).
// Under these conditions, a generic function would not be able to unmarshal the genesis state
// stored in the in-memory network because it is unmarshalling uses reflection, and it is not
// possible to reflect over a nil generic type value.

// Retrieve the supplier module's genesis state from cosmos-sdk in-memory network.
supplierGenesisState := network.GetGenesisState[*suppliertypes.GenesisState](t, suppliertypes.ModuleName, memnet)
if supplierGenesisState == nil {
t.Logf(warnNoModuleGenesisFmt, "supplier")
} else {
// Initialize on-chain accounts for genesis suppliers.
memnet.FundSupplierAccounts(t, supplierGenesisState.SupplierList...)

bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
}

// Retrieve the application module's genesis state from cosmos-sdk in-memory network.
appGenesisState := network.GetGenesisState[*apptypes.GenesisState](t, apptypes.ModuleName, memnet)
if appGenesisState == nil {
t.Logf(warnNoModuleGenesisFmt, "application")
} else {
// Initialize on-chain accounts for genesis applications.
memnet.FundAppAccounts(t, appGenesisState.ApplicationList...)
}

// Retrieve the gateway module's genesis state from cosmos-sdk in-memory network.
gatewayGenesisState := network.GetGenesisState[*gatewaytypes.GenesisState](t, gatewaytypes.ModuleName, memnet)
if gatewayGenesisState == nil {
t.Logf(warnNoModuleGenesisFmt, "gateway")
} else {
// Initialize on-chain accounts for genesis gateways.
memnet.FundGatewayAccounts(t, gatewayGenesisState.GatewayList...)
}

// need to wait for the account to be initialized in the next block
require.NoError(t, memnet.GetNetwork(t).WaitForNextBlock())
}

// FundAddress initializes an Account address and sequence number with the auth module
// by sending some tokens from the in-memory network validator, to the address provided.
// This is a necessary prerequesite in order for the account with the given address
// to be able to submit valid transactions (i.e. pay tx fees).
// NOTE: It DOES NOT associate a public key with the account. This will happen when a tx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comment!

// which is signed by the account is broadcast to the network for the first time.
func (memnet *BaseInMemoryNetwork) FundAddress(
t *testing.T,
addr types.AccAddress,
) {
t.Helper()

signerAccountNumber := 0
clientCtx := memnet.GetClientCtx(t)
net := memnet.GetNetwork(t)
val := net.Validators[0]

args := []string{
fmt.Sprintf("--%s=true", flags.FlagOffline),
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
fmt.Sprintf("--%s=%d", flags.FlagAccountNumber, signerAccountNumber),
fmt.Sprintf("--%s=%d", flags.FlagSequence, memnet.NextValidatorTxSequenceNumber(t)),
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved

fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, memnet.NewBondDenomCoins(t, 10).String()),
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
}
amount := memnet.NewBondDenomCoins(t, 200)
responseRaw, err := testcli.MsgSendExec(clientCtx, val.Address, addr, amount, args...)
require.NoError(t, err)
var responseJSON map[string]interface{}
err = json.Unmarshal(responseRaw.Bytes(), &responseJSON)
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, float64(0), responseJSON["code"], "code is not 0 in the response: %v", responseJSON)
}

// FundSupplierAccounts initializes account addresses and sequence numbers for,
// each supplier in the given list, with the auth module by sending them some tokens
// from the in-memory network validator, to the address provided. This is a necessary
// prerequisite in order for the account with the given address to be able to submit
// valid transactions (i.e. pay tx fees).
// NOTE: It DOES NOT associate a public key with the account. This will happen when a tx
// which is signed by the account is broadcast to the network for the first time.
func (memnet *BaseInMemoryNetwork) FundSupplierAccounts(
t *testing.T,
supplierList ...sharedtypes.Supplier,
) {
t.Helper()

net := memnet.GetNetwork(t)
require.NotNil(t, net, "in-memory cosmos testutil network not initialized yet, call #Start() first")

for _, supplier := range supplierList {
supplierAddr, err := types.AccAddressFromBech32(supplier.GetAddress())
require.NoError(t, err)
memnet.FundAddress(t, supplierAddr)
}
}

// FundAppAccounts initializes account addresses and sequence numbers for, each
// application in the given list, with the auth module by sending them some tokens
// from the in-memory network validator, to the address provided. This is a necessary
// prerequisite in order for the account with the given address to be able to submit
// valid transactions (i.e. pay tx fees).
// NOTE: It DOES NOT associate a public key with the account. This will happen when a tx
// which is signed by the account is broadcast to the network for the first time.
func (memnet *BaseInMemoryNetwork) FundAppAccounts(
t *testing.T,
appList ...apptypes.Application,
) {
t.Helper()

for _, application := range appList {
appAddr, err := types.AccAddressFromBech32(application.GetAddress())
require.NoError(t, err)
memnet.FundAddress(t, appAddr)
}
}

// FundGatewayAccounts initializes account addresses and sequence numbers for, each
// gateway in the given list, with the auth module by sending them some tokens
// from the in-memory network validator, to the address provided. This is a necessary
// prerequisite in order for the account with the given address to be able to submit
// valid transactions (i.e. pay tx fees).
// NOTE: It DOES NOT associate a public key with the account. This will happen when a tx
// which is signed by the account is broadcast to the network for the first time.
func (memnet *BaseInMemoryNetwork) FundGatewayAccounts(
t *testing.T,
gatewayList ...gatewaytypes.Gateway,
) {
t.Helper()

for _, gateway := range gatewayList {
gatewayAddr, err := types.AccAddressFromBech32(gateway.GetAddress())
require.NoError(t, err)
memnet.FundAddress(t, gatewayAddr)
}
}

func (memnet *BaseInMemoryNetwork) NewBondDenomCoins(t *testing.T, numCoins int64) sdk.Coins {
t.Helper()

return sdk.NewCoins(sdk.NewCoin(memnet.GetNetwork(t).Config.BondDenom, math.NewInt(numCoins)))
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
}
130 changes: 130 additions & 0 deletions testutil/network/basenet/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package basenet

import (
"context"
"sync/atomic"
"testing"

"github.com/cosmos/cosmos-sdk/client"
sdknetwork "github.com/cosmos/cosmos-sdk/testutil/network"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/network"
"github.com/pokt-network/poktroll/testutil/testkeyring"
)

var _ network.InMemoryNetwork = (*BaseInMemoryNetwork)(nil)

// BaseInMemoryNetwork is an "abstract" (i.e. partial) implementation, intended
// to consolidate shared behavior between multiple ("concrete") InMemoryNetwork
// implementations. These shared behaviors (methods) are accessible to any concrete
// implementation which embeds BaseInMemoryNetwork.
type BaseInMemoryNetwork struct {
Config network.InMemoryNetworkConfig
PreGeneratedAccountIterator *testkeyring.PreGeneratedAccountIterator
CosmosNetwork *sdknetwork.Network

// lastValidatorSeqNumber stores the last (most recently generated) account sequence number.
// NB: explicitly NOT using atomic.Int32 as it's usage doesn't compose well with anonymous
bryanchriswhite marked this conversation as resolved.
Show resolved Hide resolved
// literal declarations.
lastValidatorSeqNumber int32
}

// NewBaseInMemoryNetwork creates a new BaseInMemoryNetwork with the given
// configuration and pre-generated accounts. Intended to be used in constructor
// functions of structs that embed BaseInMemoryNetwork.
func NewBaseInMemoryNetwork(
t *testing.T,
cfg *network.InMemoryNetworkConfig,
preGeneratedAccounts *testkeyring.PreGeneratedAccountIterator,
) *BaseInMemoryNetwork {
t.Helper()

return &BaseInMemoryNetwork{
Config: *cfg,
PreGeneratedAccountIterator: preGeneratedAccounts,

// First functional account sequence number is 1. Starting at 0 so that
// callers can always use NextValidatorTxSequenceNumber() (no boundary condition).
lastValidatorSeqNumber: int32(0),
}
}

// InitializeDefaults sets the underlying cosmos-sdk testutil network config to
// a reasonable default in case one was not provided with the InMemoryNetworkConfig.
func (memnet *BaseInMemoryNetwork) InitializeDefaults(t *testing.T) {
if memnet.Config.CosmosCfg != nil {
t.Log("Cosmos config already initialized, using existing config")
return
}

t.Log("Cosmos config not initialized, using default config")
// Initialize a network config.
cfg := network.DefaultConfig()
memnet.Config.CosmosCfg = &cfg
}

// GetClientCtx returns the underlying cosmos-sdk testutil network's client context.
func (memnet *BaseInMemoryNetwork) GetClientCtx(t *testing.T) client.Context {
t.Helper()

// Only the first validator's client context is populated.
// (see: https://pkg.go.dev/github.com/cosmos/cosmos-sdk/testutil/network#pkg-overview)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for linking to it!

ctx := memnet.GetNetwork(t).Validators[0].ClientCtx

// TODO_NEXT(@bryanchriswhite): Ensure validator key is always available.

// Overwrite the client context's Keyring with the in-memory one that contains
// our pre-generated accounts.
return ctx.WithKeyring(memnet.Config.Keyring)
}

// GetConfig returns the InMemoryNetworkConfig which associated with a given
// InMemoryNetwork instance.
func (memnet *BaseInMemoryNetwork) GetConfig(t *testing.T) *network.InMemoryNetworkConfig {
t.Helper()

return &memnet.Config
}

// GetCosmosNetworkConfig returns the underlying cosmos-sdk testutil network config.
// It requires that the config has been set, failing the test if not.
func (memnet *BaseInMemoryNetwork) GetCosmosNetworkConfig(t *testing.T) *sdknetwork.Config {
t.Helper()

require.NotEmptyf(t, memnet.Config, "in-memory network config not set")
return memnet.Config.CosmosCfg
}

// GetNetwork returns the underlying cosmos-sdk testutil network instance.
// It requires that the cosmos-sdk in-memory network has been set, failing the test if not.
func (memnet *BaseInMemoryNetwork) GetNetwork(t *testing.T) *sdknetwork.Network {
t.Helper()

require.NotEmptyf(t, memnet.CosmosNetwork, "in-memory cosmos network not set")
return memnet.CosmosNetwork
}

// GetLastValidatorTxSequenceNumber returns the last (most recently generated) account sequence number.
// It is safe for concurrent use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

func (memnet *BaseInMemoryNetwork) GetLastValidatorTxSequenceNumber(t *testing.T) int {
t.Helper()

return int(atomic.LoadInt32(&memnet.lastValidatorSeqNumber))
}

// NextValidatorTxSequenceNumber increments the account sequence number and returns the new value.
// It is safe for concurrent use.
func (memnet *BaseInMemoryNetwork) NextValidatorTxSequenceNumber(t *testing.T) int {
t.Helper()

return int(atomic.AddInt32(&memnet.lastValidatorSeqNumber, 1))
}

// Start is a stub which is expected to be implemented by "concrete" InMemoryNetwork
// implementations. As BaseInMemoryNetwork is intended to be an "abstract" implementation,
// it is too general to define this behavior, leaving it up to embedders. As a result,
// this function panics if it is called.
func (memnet *BaseInMemoryNetwork) Start(_ context.Context, t *testing.T) {
panic("must be implemented by struct embedders")
}
Loading
Loading