testutils

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumTokensPerWallet         = 1000000
	TokenQuantityPrecision     = 64
	SelectQuantity             = "100"
	TxID                       = "someTxID"
	TokenType                  = "USD"
	SelectorNumRetries         = 3
	SelectorTimeout            = 5 * time.Second
	LockSleepTimeout           = 2 * time.Second
	LockValidTxEvictionTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func NewEnhancedManager

func NewEnhancedManager(t *testing.T, manager token2.SelectorManager, tokenDB driver.TokenStore) *enhancedManager

func TestHotTokenContention added in v0.24.0

func TestHotTokenContention(t *testing.T, replicas []EnhancedManager)

TestHotTokenContention mirrors the incident reported in #2395: a wallet with a few small tokens and one much larger one, and far more concurrent requests than tokens. Every request asks for CHF1, satisfiable either by a small token directly or by the large one — which recycles most of its value back as a freshly-minted token via deleteTokensAndStoreChange, so at any instant there is exactly one "big" token in the pool. That is the hot token every losing goroutine keeps re-targeting after a lost lock race, absent a per-attempt blacklist (mechanism 1 in #2395) or an anti-join against already-locked tokens (mechanism 3).

Unlike the other cases in this file, callers are expected to also inspect lock-conflict counts (see sherdlock's TestHotTokenContention, which wraps the Locker to record them) and assert on their distribution — this function only asserts the functional invariant that must hold regardless of how contention is distributed: total demand exactly matches the wallet balance, so no error here can be a genuine insufficient-funds; any error is spurious, caused by contention.

func TestInsufficientTokensManyReplicas

func TestInsufficientTokensManyReplicas(t *testing.T, replicas []EnhancedManager)

func TestInsufficientTokensOneReplica

func TestInsufficientTokensOneReplica(t *testing.T, replica EnhancedManager)

func TestSufficientTokensBigDenominationsManyReplicas

func TestSufficientTokensBigDenominationsManyReplicas(t *testing.T, replicas []EnhancedManager)

func TestSufficientTokensBigDenominationsOneReplica

func TestSufficientTokensBigDenominationsOneReplica(t *testing.T, replica EnhancedManager)

func TestSufficientTokensManyReplicas

func TestSufficientTokensManyReplicas(t *testing.T, replicas []EnhancedManager)

func TestSufficientTokensOneReplica

func TestSufficientTokensOneReplica(t *testing.T, replica EnhancedManager)

Types

type EnhancedManager

type EnhancedManager interface {
	token2.SelectorManager
	TokenSum() (token.Quantity, error)
	UpdateTokens(spentTokens []*token.ID, addedTokens []token.UnspentToken) error
}

type MockIterator

type MockIterator struct {
	// contains filtered or unexported fields
}

func (*MockIterator) Close

func (m *MockIterator) Close()

func (*MockIterator) Next

func (m *MockIterator) Next() (*token2.UnspentToken, error)

type MockQueryService

type MockQueryService struct {
	// contains filtered or unexported fields
}

func NewMockQueryService

func NewMockQueryService() *MockQueryService

func (*MockQueryService) Add

func (q *MockQueryService) Add(key string, t *token2.UnspentToken)

func (*MockQueryService) GetStatus

func (q *MockQueryService) GetStatus(ctx context.Context, txID string) (token.TxStatus, string, error)

func (*MockQueryService) GetTokens

func (q *MockQueryService) GetTokens(ctx context.Context, inputs ...*token2.ID) ([]*token2.Token, error)

func (*MockQueryService) GetUnspentToken

func (q *MockQueryService) GetUnspentToken(_ context.Context, tokenID *token2.ID) *token2.UnspentToken

func (*MockQueryService) GetUnspentTokens

func (q *MockQueryService) GetUnspentTokens(_ context.Context, inputs ...*token2.ID) ([]*token2.UnspentToken, error)

func (*MockQueryService) SpendableTokensIteratorBy

func (q *MockQueryService) SpendableTokensIteratorBy(ctx context.Context, walletID string, typ token2.Type) (driver.SpendableTokensIterator, error)

func (*MockQueryService) UnspentTokensIterator

func (q *MockQueryService) UnspentTokensIterator(context.Context) (*token.UnspentTokensIterator, error)

func (*MockQueryService) UnspentTokensIteratorBy

func (q *MockQueryService) UnspentTokensIteratorBy(_ context.Context, walletID string, _ token2.Type) (driver.UnspentTokensIterator, error)

func (*MockQueryService) WarmupCache

func (q *MockQueryService) WarmupCache(walletID, tokenType string)

type MockVault

type MockVault struct {
}

func (*MockVault) GetStatus

func (m *MockVault) GetStatus(ctx context.Context, txID string) (ttxdb.TxStatus, string, error)

type NoLock

type NoLock struct {
}

func (*NoLock) IsLocked

func (n *NoLock) IsLocked(id *token2.ID) bool

func (*NoLock) Lock

func (n *NoLock) Lock(_ context.Context, _ string, _ *token2.ID, _ string, _ bool) (string, error)

func (*NoLock) UnlockByTxID

func (n *NoLock) UnlockByTxID(ctx context.Context, txID string)

func (*NoLock) UnlockIDs

func (n *NoLock) UnlockIDs(_ context.Context, _ string, ids ...*token2.ID) []*token2.ID

type TokenFilter

type TokenFilter struct {
	Wallet   []byte
	WalletID string
}

func (*TokenFilter) ContainsToken

func (c *TokenFilter) ContainsToken(token *token2.UnspentToken) bool

func (*TokenFilter) ID

func (c *TokenFilter) ID() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL