func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, error) { cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg.NewDB = func(path string) (ethdb.Database, error) { return ethdb.NewMemDatabase() } cfg.MaxPeers = 0 // disable network cfg.Shh = false // disable whisper cfg.NAT = nil // disable port mapping ethereum, err := eth.New(cfg) if err != nil { return nil, err } // import the genesis block ethereum.ResetWithGenesisBlock(test.Genesis) // import pre accounts _, err = test.InsertPreState(ethereum) if err != nil { return ethereum, fmt.Errorf("InsertPreState: %v", err) } cm := ethereum.ChainManager() validBlocks, err := test.TryBlocksInsert(cm) if err != nil { return ethereum, fmt.Errorf("Block Test load error: %v", err) } newDB := cm.State() if err := test.ValidatePostState(newDB); err != nil { return ethereum, fmt.Errorf("post state validation failed: %v", err) } return ethereum, test.ValidateImportedHeaders(cm, validBlocks) }
// MakeSystemNode configures a protocol stack for the RPC tests based on a given // keystore path and initial pre-state. func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node.Node, error) { // Create a networkless protocol stack stack, err := node.New(&node.Config{ IPCPath: node.DefaultIPCEndpoint(), HTTPHost: common.DefaultHTTPHost, HTTPPort: common.DefaultHTTPPort, HTTPModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, WSHost: common.DefaultWSHost, WSPort: common.DefaultWSPort, WSModules: []string{"admin", "db", "eth", "debug", "miner", "net", "shh", "txpool", "personal", "web3"}, NoDiscovery: true, }) if err != nil { return nil, err } // Create the keystore and inject an unlocked account if requested accman := accounts.NewPlaintextManager(keydir) if len(privkey) > 0 { key, err := crypto.HexToECDSA(privkey) if err != nil { return nil, err } a, err := accman.ImportECDSA(key, "") if err != nil { return nil, err } if err := accman.Unlock(a, ""); err != nil { return nil, err } } // Initialize and register the Ethereum protocol db, _ := ethdb.NewMemDatabase() if _, err := test.InsertPreState(db); err != nil { return nil, err } ethConf := ð.Config{ TestGenesisState: db, TestGenesisBlock: test.Genesis, ChainConfig: &core.ChainConfig{HomesteadBlock: params.MainNetHomesteadBlock}, AccountManager: accman, } if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { return eth.New(ctx, ethConf) }); err != nil { return nil, err } // Initialize and register the Whisper protocol if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisper.New(), nil }); err != nil { return nil, err } return stack, nil }
func runOneBlockTest(ctx *cli.Context, test *tests.BlockTest) (*eth.Ethereum, error) { // TODO remove in favor of logic contained in tests package cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx) cfg.NewDB = func(path string) (common.Database, error) { return ethdb.NewMemDatabase() } cfg.MaxPeers = 0 // disable network cfg.Shh = false // disable whisper cfg.NAT = nil // disable port mapping ethereum, err := eth.New(cfg) if err != nil { return nil, err } // if err := ethereum.Start(); err != nil { // return nil, err // } // import the genesis block ethereum.ResetWithGenesisBlock(test.Genesis) // import pre accounts statedb, err := test.InsertPreState(ethereum) if err != nil { return ethereum, fmt.Errorf("InsertPreState: %v", err) } if err := test.TryBlocksInsert(ethereum.ChainManager()); err != nil { return ethereum, fmt.Errorf("Block Test load error: %v", err) } if err := test.ValidatePostState(statedb); err != nil { return ethereum, fmt.Errorf("post state validation failed: %v", err) } return ethereum, nil }
// RunTest executes the specified test against an already pre-configured protocol // stack to ensure basic checks pass before running RPC tests. func RunTest(stack *node.Node, test *tests.BlockTest) error { var ethereum *eth.Ethereum stack.Service(ðereum) blockchain := ethereum.BlockChain() // Process the blocks and verify the imported headers blocks, err := test.TryBlocksInsert(blockchain) if err != nil { return err } if err := test.ValidateImportedHeaders(blockchain, blocks); err != nil { return err } // Retrieve the assembled state and validate it stateDb, err := blockchain.State() if err != nil { return err } if err := test.ValidatePostState(stateDb); err != nil { return err } return nil }