neosimulation

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package neosimulation provides simulation service for automated transaction testing.

Package neosimulation provides contract invocation capabilities for the simulation service. All contract invocations use pool accounts managed by the neoaccounts service. Private keys never leave the TEE - signing happens inside the account pool service.

Package neosimulation provides simulation service for automated transaction testing.

Package neosimulation provides MiniApp workflow simulation.

Package neosimulation provides simulation service for automated transaction testing. This service simulates real user transactions by: - Requesting accounts from the pool - Simulating transactions (payGAS with random amounts) - Recording transactions to Supabase - Releasing accounts back to the pool

Package neosimulation provides MiniApp workflow simulation.

Package neosimulation provides simulation service for automated transaction testing.

Index

Constants

View Source
const (
	ServiceID   = "neosimulation"
	ServiceName = "Neo Simulation Service"
	Version     = "1.0.0"

	// Default simulation interval range (15 seconds per miniapp)
	// Single worker per miniapp with fixed 15-second interval
	DefaultMinIntervalMS = 15000 // 15 seconds minimum per worker
	DefaultMaxIntervalMS = 15000 // 15 seconds maximum per worker

	// Default number of concurrent workers per miniapp
	// Single worker for consistent 15-second interval
	DefaultWorkersPerApp = 1

	// Default simulation transaction amounts (in GAS smallest unit, 8 decimals)
	DefaultMinAmount = 1000000   // 0.01 GAS
	DefaultMaxAmount = 100000000 // 1 GAS
)

Variables

View Source
var (
	ErrPriceFeedNotConfigured     = errors.New("price feed address not configured")
	ErrRandomnessLogNotConfigured = errors.New("randomness log address not configured")
	ErrPaymentHubNotConfigured    = errors.New("payment hub address not configured")
	ErrMiniAppContractNotFound    = errors.New("miniapp contract not found")
)
View Source
var DefaultMiniApps = []string{
	"miniapp-lottery",
	"miniapp-coinflip",
	"miniapp-dice-game",
	"miniapp-scratch-card",
	"miniapp-red-envelope",
	"miniapp-time-capsule",
	"miniapp-neo-crash",
}

DefaultMiniApps is the list of MiniApps configured in PaymentHub contract. Only these apps can receive payments via PaymentHub.pay().

Functions

This section is empty.

Types

type Config

type Config struct {
	Marble         interface{} // *marble.Marble
	DB             interface{} // database.RepositoryInterface
	ChainClient    interface{} // *chain.Client
	AccountPoolURL string
	MiniApps       []string // List of app IDs to simulate
	MinIntervalMS  int      // Minimum interval between transactions (milliseconds)
	MaxIntervalMS  int      // Maximum interval between transactions (milliseconds)
	MinAmount      int64    // Minimum transaction amount
	MaxAmount      int64    // Maximum transaction amount
	WorkersPerApp  int      // Number of concurrent workers per miniapp
	AutoStart      bool     // Start simulation automatically on service start
}

Config holds simulation service configuration.

type ContractInvoker

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

ContractInvoker handles smart contract invocations using pool accounts. All signing happens inside the TEE via the account pool service.

func NewContractInvoker

func NewContractInvoker(cfg ContractInvokerConfig) (*ContractInvoker, error)

NewContractInvoker creates a new contract invoker using pool accounts.

func NewContractInvokerFromEnv

func NewContractInvokerFromEnv(poolClient *neoaccountsclient.Client) (*ContractInvoker, error)

NewContractInvokerFromEnv creates a contract invoker from environment variables. This is a convenience function for creating the invoker with standard configuration.

func (*ContractInvoker) Close

func (inv *ContractInvoker) Close()

Close releases all accounts and cleans up resources.

func (*ContractInvoker) GetLockedAccountCount

func (inv *ContractInvoker) GetLockedAccountCount() int

GetLockedAccountCount returns the number of currently locked accounts.

func (*ContractInvoker) GetMiniAppContractAddress

func (inv *ContractInvoker) GetMiniAppContractAddress(appID string) (string, error)

GetMiniAppContractAddress returns the contract address for a MiniApp.

func (*ContractInvoker) GetPriceSymbols

func (inv *ContractInvoker) GetPriceSymbols() []string

GetPriceSymbols returns the list of price feed symbols.

func (*ContractInvoker) GetStats

func (inv *ContractInvoker) GetStats() map[string]interface{}

GetStats returns contract invocation statistics.

func (*ContractInvoker) HasMiniAppContract

func (inv *ContractInvoker) HasMiniAppContract(appID string) bool

HasMiniAppContract checks if a MiniApp contract is configured.

func (*ContractInvoker) HasPaymentHub

func (inv *ContractInvoker) HasPaymentHub() bool

func (*ContractInvoker) HasPriceFeed

func (inv *ContractInvoker) HasPriceFeed() bool

func (*ContractInvoker) HasRandomnessLog

func (inv *ContractInvoker) HasRandomnessLog() bool

func (*ContractInvoker) InvokeMiniAppContract

func (inv *ContractInvoker) InvokeMiniAppContract(ctx context.Context, appID, method string, params []neoaccountsclient.ContractParam) (string, error)

InvokeMiniAppContract invokes a method on a MiniApp contract.

func (*ContractInvoker) PayToApp

func (inv *ContractInvoker) PayToApp(ctx context.Context, appID string, amount int64, memo string) (string, error)

PayToApp makes a payment to a MiniApp via direct GAS.Transfer with data. This simulates real user behavior where users pay from their own wallets. The pool account must have sufficient GAS for the payment + transaction fees.

Payment Flow (Direct GAS.Transfer with data): 1. Pool account calls TransferWithData which uses neo-go SDK's actor pattern 2. GAS contract transfers GAS to PaymentHub with appId as data 3. PaymentHub.OnNEP17Payment callback is triggered 4. PaymentHub validates appId and updates balance 5. Receipt is created and PaymentReceived event is emitted

func (*ContractInvoker) PayoutToUser

func (inv *ContractInvoker) PayoutToUser(ctx context.Context, appID string, userAddress string, amount int64, memo string) (string, error)

PayoutToUser sends a callback payout from a MiniApp's pool account to a user address. This simulates the platform paying out winnings to users who won games. The pool account must have sufficient GAS for the payout + transaction fees.

func (*ContractInvoker) RecordRandomness

func (inv *ContractInvoker) RecordRandomness(ctx context.Context) (string, error)

RecordRandomness records a randomness value on-chain using the master wallet. RandomnessLog requires the caller to be a registered TEE signer in AppRegistry.

func (*ContractInvoker) ReleaseAllAccounts

func (inv *ContractInvoker) ReleaseAllAccounts(ctx context.Context)

ReleaseAllAccounts releases all locked accounts back to the pool.

func (*ContractInvoker) UpdatePriceFeed

func (inv *ContractInvoker) UpdatePriceFeed(ctx context.Context, symbol string) (string, error)

UpdatePriceFeed updates a price feed with simulated data using the master wallet. PriceFeed requires the caller to be a registered TEE signer in AppRegistry.

type ContractInvokerConfig

type ContractInvokerConfig struct {
	PoolClient                 PoolClientInterface
	PriceFeedAddress           string
	RandomnessLogAddress       string
	PaymentHubAddress          string
	ServiceLayerGatewayAddress string
	MiniAppContracts           map[string]string // appID -> contract address
}

ContractInvokerConfig holds configuration for the contract invoker.

type ContractInvokerInterface

type ContractInvokerInterface interface {
	UpdatePriceFeed(ctx context.Context, symbol string) (string, error)
	RecordRandomness(ctx context.Context) (string, error)
	PayToApp(ctx context.Context, appID string, amount int64, memo string) (string, error)
	PayoutToUser(ctx context.Context, appID string, userAddress string, amount int64, memo string) (string, error)
	// MiniApp contract methods
	HasMiniAppContract(appID string) bool
	GetMiniAppContractAddress(appID string) (string, error)
	InvokeMiniAppContract(ctx context.Context, appID, method string, params []neoaccountsclient.ContractParam) (string, error)
	// Stats and management
	GetStats() map[string]interface{}
	GetPriceSymbols() []string
	GetLockedAccountCount() int
	ReleaseAllAccounts(ctx context.Context)
	Close()
}

ContractInvokerInterface defines the interface for contract invocation operations. This interface allows for dependency injection and easier testing.

type MiniAppConfig

type MiniAppConfig struct {
	AppID       string
	Name        string
	Category    string
	Interval    time.Duration
	BetAmount   int64 // in 8 decimals (1 GAS = 100000000)
	Description string
}

MiniAppConfig holds configuration for each MiniApp.

func AllMiniApps

func AllMiniApps() []MiniAppConfig

AllMiniApps returns configuration for all builtin MiniApps. NOTE: Reduced to 10 core apps for stability (2026-01-08) IMPORTANT: AppIDs use miniapp- prefix as the standard naming convention

type MiniAppSimulator

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

MiniAppSimulator simulates all MiniApp workflows.

func NewMiniAppSimulator

func NewMiniAppSimulator(invoker ContractInvokerInterface, userAddresses []string, recordTx TxRecordFunc) *MiniAppSimulator

NewMiniAppSimulator creates a new MiniApp simulator.

func (*MiniAppSimulator) GetStats

func (s *MiniAppSimulator) GetStats() map[string]interface{}

GetStats returns current simulation statistics.

func (*MiniAppSimulator) SimulateBreakupContract

func (s *MiniAppSimulator) SimulateBreakupContract(ctx context.Context) error

SimulateBreakupContract simulates breakup contract creation.

func (*MiniAppSimulator) SimulateBurnLeague

func (s *MiniAppSimulator) SimulateBurnLeague(ctx context.Context) error

SimulateBurnLeague simulates burn-to-earn.

func (*MiniAppSimulator) SimulateCandidateVote

func (s *MiniAppSimulator) SimulateCandidateVote(ctx context.Context) error

SimulateCandidateVote simulates candidate voting.

func (*MiniAppSimulator) SimulateCanvas

func (s *MiniAppSimulator) SimulateCanvas(ctx context.Context) error

SimulateCanvas simulates collaborative canvas drawing.

func (*MiniAppSimulator) SimulateCoinFlip

func (s *MiniAppSimulator) SimulateCoinFlip(ctx context.Context) error

SimulateCoinFlip simulates the coin flip workflow. Business flow: PlaceBet -> RequestRNG -> ResolveBet

func (*MiniAppSimulator) SimulateCompoundCapsule

func (s *MiniAppSimulator) SimulateCompoundCapsule(ctx context.Context) error

SimulateCompoundCapsule simulates auto-compounding savings.

func (*MiniAppSimulator) SimulateCryptoRiddle

func (s *MiniAppSimulator) SimulateCryptoRiddle(ctx context.Context) error

SimulateCryptoRiddle simulates password red envelope.

func (*MiniAppSimulator) SimulateDailyCheckin

func (s *MiniAppSimulator) SimulateDailyCheckin(ctx context.Context) error

SimulateDailyCheckin simulates daily check-in workflow. Business flow: Pay fee -> CheckIn -> (optionally) ClaimRewards

func (*MiniAppSimulator) SimulateDevTipping

func (s *MiniAppSimulator) SimulateDevTipping(ctx context.Context) error

SimulateDevTipping simulates the EcoBoost developer tipping app.

func (*MiniAppSimulator) SimulateDiceGame

func (s *MiniAppSimulator) SimulateDiceGame(ctx context.Context) error

SimulateDiceGame simulates the dice game workflow. Business flow: PlaceBet -> RequestRNG -> RollDice

func (*MiniAppSimulator) SimulateDoomsdayClock

func (s *MiniAppSimulator) SimulateDoomsdayClock(ctx context.Context) error

SimulateDoomsdayClock simulates the FOMO3D style game. Business flow: BuyKeys -> ExtendTimer -> WinPot (if last buyer)

func (*MiniAppSimulator) SimulateExFiles

func (s *MiniAppSimulator) SimulateExFiles(ctx context.Context) error

SimulateExFiles simulates ex-files sharing.

func (*MiniAppSimulator) SimulateFlashLoan

func (s *MiniAppSimulator) SimulateFlashLoan(ctx context.Context) error

SimulateFlashLoan simulates the flash loan workflow. Business flow: RequestLoan -> Execute arbitrage -> Repay

func (*MiniAppSimulator) SimulateFogPuzzle

func (s *MiniAppSimulator) SimulateFogPuzzle(ctx context.Context) error

SimulateFogPuzzle simulates fog of war puzzle.

func (*MiniAppSimulator) SimulateGardenOfNeo

func (s *MiniAppSimulator) SimulateGardenOfNeo(ctx context.Context) error

SimulateGardenOfNeo simulates virtual garden planting.

func (*MiniAppSimulator) SimulateGasCircle

func (s *MiniAppSimulator) SimulateGasCircle(ctx context.Context) error

SimulateGasCircle simulates daily savings circle with lottery. Business flow: CreateCircle -> JoinCircle -> MakeDeposit -> RequestPayout

func (*MiniAppSimulator) SimulateGasSpin

func (s *MiniAppSimulator) SimulateGasSpin(ctx context.Context) error

SimulateGasSpin simulates the gas spin wheel workflow. Business flow: PlaceSpin -> RequestRNG -> SpinResult

func (*MiniAppSimulator) SimulateGovBooster

func (s *MiniAppSimulator) SimulateGovBooster(ctx context.Context) error

SimulateGovBooster simulates bNEO governance optimization. Business flow: RequestBoost -> VerifyStake -> ApplyBoost

func (*MiniAppSimulator) SimulateGovMerc

func (s *MiniAppSimulator) SimulateGovMerc(ctx context.Context) error

SimulateGovMerc simulates governance mercenary voting.

func (*MiniAppSimulator) SimulateGrantShare

func (s *MiniAppSimulator) SimulateGrantShare(ctx context.Context) error

SimulateGrantShare simulates community grant funding. Business flow: CreateGrant -> FundGrant -> WithdrawFunds

func (*MiniAppSimulator) SimulateGraveyard

func (s *MiniAppSimulator) SimulateGraveyard(ctx context.Context) error

SimulateGraveyard simulates digital graveyard.

func (*MiniAppSimulator) SimulateGuardianPolicy

func (s *MiniAppSimulator) SimulateGuardianPolicy(ctx context.Context) error

SimulateGuardianPolicy simulates guardian policy setup.

func (*MiniAppSimulator) SimulateHeritageTrust

func (s *MiniAppSimulator) SimulateHeritageTrust(ctx context.Context) error

SimulateHeritageTrust simulates living trust DAO.

func (*MiniAppSimulator) SimulateLottery

func (s *MiniAppSimulator) SimulateLottery(ctx context.Context) error

SimulateLottery simulates the lottery workflow. Business flow: BuyTickets -> InitiateDraw -> DrawWinner

func (*MiniAppSimulator) SimulateMasqueradeDAO

func (s *MiniAppSimulator) SimulateMasqueradeDAO(ctx context.Context) error

SimulateMasqueradeDAO simulates anonymous DAO voting.

func (*MiniAppSimulator) SimulateMegaMillions

func (s *MiniAppSimulator) SimulateMegaMillions(ctx context.Context) error

SimulateMegaMillions simulates the mega millions lottery workflow. Business flow: BuyTicket -> InitiateDraw -> DrawCompleted

func (*MiniAppSimulator) SimulateMicroPredict

func (s *MiniAppSimulator) SimulateMicroPredict(ctx context.Context) error

SimulateMicroPredict simulates 60-second price predictions. Business flow: PlacePrediction -> RequestResolve

func (*MiniAppSimulator) SimulateMillionPieceMap

func (s *MiniAppSimulator) SimulateMillionPieceMap(ctx context.Context) error

SimulateMillionPieceMap simulates pixel map purchases.

func (*MiniAppSimulator) SimulateNeoCrash

func (s *MiniAppSimulator) SimulateNeoCrash(ctx context.Context) error

SimulateNeoCrash simulates the crash game workflow. Business flow: PlaceBet -> WatchMultiplier -> CashOut (before crash)

func (*MiniAppSimulator) SimulateNeoNS

func (s *MiniAppSimulator) SimulateNeoNS(ctx context.Context) error

SimulateNeoNS simulates Neo Name Service domain registration. Business flow: SearchDomain -> RegisterDomain -> RenewDomain

func (*MiniAppSimulator) SimulateNeoburger

func (s *MiniAppSimulator) SimulateNeoburger(ctx context.Context) error

SimulateNeoburger simulates NEO staking via NeoBurger.

func (*MiniAppSimulator) SimulateOnChainTarot

func (s *MiniAppSimulator) SimulateOnChainTarot(ctx context.Context) error

SimulateOnChainTarot simulates tarot card readings.

func (*MiniAppSimulator) SimulatePuzzleMining

func (s *MiniAppSimulator) SimulatePuzzleMining(ctx context.Context) error

SimulatePuzzleMining simulates puzzle solving for rewards.

func (*MiniAppSimulator) SimulateRedEnvelope

func (s *MiniAppSimulator) SimulateRedEnvelope(ctx context.Context) error

SimulateRedEnvelope simulates social GAS red packets. Business flow: CreateEnvelope -> Claim (multiple times)

func (*MiniAppSimulator) SimulateScratchCard

func (s *MiniAppSimulator) SimulateScratchCard(ctx context.Context) error

SimulateScratchCard simulates the scratch card workflow. Business flow: BuyCard -> RequestRNG -> RevealCard

func (*MiniAppSimulator) SimulateSecretPoker

func (s *MiniAppSimulator) SimulateSecretPoker(ctx context.Context) error

SimulateSecretPoker simulates TEE Texas Hold'em. Business flow: CreateTable -> JoinTable -> StartHand

func (*MiniAppSimulator) SimulateSelfLoan

func (s *MiniAppSimulator) SimulateSelfLoan(ctx context.Context) error

SimulateSelfLoan simulates self-repaying loans.

func (*MiniAppSimulator) SimulateThroneOfGas

func (s *MiniAppSimulator) SimulateThroneOfGas(ctx context.Context) error

SimulateThroneOfGas simulates the king of the hill game. Business flow: ClaimThrone -> CollectTax

func (*MiniAppSimulator) SimulateTimeCapsule

func (s *MiniAppSimulator) SimulateTimeCapsule(ctx context.Context) error

SimulateTimeCapsule simulates the TEE time capsule workflow. Business flow: Bury (encrypt) -> Fish (random pickup) -> Reveal (time unlock)

func (*MiniAppSimulator) SimulateUnbreakableVault

func (s *MiniAppSimulator) SimulateUnbreakableVault(ctx context.Context) error

SimulateUnbreakableVault simulates time-locked vault.

type PoolClientInterface

type PoolClientInterface interface {
	RequestAccounts(ctx context.Context, count int, purpose string) (*neoaccountsclient.RequestAccountsResponse, error)
	ReleaseAccounts(ctx context.Context, accountIDs []string) (*neoaccountsclient.ReleaseAccountsResponse, error)
	InvokeContract(ctx context.Context, accountID, contractAddress, method string, params []neoaccountsclient.ContractParam, scope string) (*neoaccountsclient.InvokeContractResponse, error)
	InvokeMaster(ctx context.Context, contractAddress, method string, params []neoaccountsclient.ContractParam, scope string) (*neoaccountsclient.InvokeContractResponse, error)
	FundAccount(ctx context.Context, toAddress string, amount int64) (*neoaccountsclient.FundAccountResponse, error)
	Transfer(ctx context.Context, accountID, toAddress string, amount int64, tokenAddress string) (*neoaccountsclient.TransferResponse, error)
	TransferWithData(ctx context.Context, accountID, toAddress string, amount int64, data string) (*neoaccountsclient.TransferWithDataResponse, error)
}

PoolClientInterface defines the interface for pool client operations used by ContractInvoker. This interface allows for dependency injection and easier testing.

type Service

type Service struct {
	*commonservice.BaseService
	// contains filtered or unexported fields
}

Service implements the simulation service.

func New

func New(cfg Config) (*Service, error)

New creates a new simulation service.

func (*Service) GetStatus

func (s *Service) GetStatus() *SimulationStatus

GetStatus returns the current simulation status.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start starts the simulation.

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the simulation.

type SimulationStatus

type SimulationStatus struct {
	Running       bool              `json:"running"`
	MiniApps      []string          `json:"mini_apps"`
	MinIntervalMS int               `json:"min_interval_ms"`
	MaxIntervalMS int               `json:"max_interval_ms"`
	TxCounts      map[string]int64  `json:"tx_counts"`     // Per-app transaction counts
	LastTxTimes   map[string]string `json:"last_tx_times"` // Per-app last transaction time
	StartedAt     *time.Time        `json:"started_at,omitempty"`
	Uptime        string            `json:"uptime,omitempty"`
}

SimulationStatus represents the current simulation status.

type SimulationTx

type SimulationTx struct {
	ID             int64     `json:"id"`
	AppID          string    `json:"app_id"`
	AccountAddress string    `json:"account_address"`
	TxType         string    `json:"tx_type"`
	Amount         int64     `json:"amount,omitempty"`
	Status         string    `json:"status"`
	TxHash         string    `json:"tx_hash,omitempty"`
	CreatedAt      time.Time `json:"created_at"`
}

SimulationTx represents a simulated transaction record.

type StartSimulationRequest

type StartSimulationRequest struct {
	MiniApps      []string `json:"mini_apps,omitempty"`       // Override configured MiniApps
	MinIntervalMS int      `json:"min_interval_ms,omitempty"` // Override min interval
	MaxIntervalMS int      `json:"max_interval_ms,omitempty"` // Override max interval
}

StartSimulationRequest is the request to start simulation.

type StartSimulationResponse

type StartSimulationResponse struct {
	Success  bool     `json:"success"`
	Message  string   `json:"message,omitempty"`
	MiniApps []string `json:"mini_apps"`
	Running  bool     `json:"running"`
}

StartSimulationResponse is the response for starting simulation.

type StopSimulationRequest

type StopSimulationRequest struct{}

StopSimulationRequest is the request to stop simulation.

type StopSimulationResponse

type StopSimulationResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
	Running bool   `json:"running"`
}

StopSimulationResponse is the response for stopping simulation.

type TxRecordFunc

type TxRecordFunc func(appID, accountAddress, txType string, amount int64, status, txHash string) error

TxRecordFunc is a callback function to record transactions to the database.

Jump to

Keyboard shortcuts

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