()
| 91 | } |
| 92 | |
| 93 | func (t *BlockTest) Run() error { |
| 94 | config, ok := Forks[t.json.Network] |
| 95 | if !ok { |
| 96 | return UnsupportedForkError{t.json.Network} |
| 97 | } |
| 98 | |
| 99 | // import pre accounts & construct test genesis block & state root |
| 100 | db := database.NewMemDatabase() |
| 101 | remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter()) |
| 102 | gblock, err := t.genesis(config).Commit(db) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | if gblock.Hash() != t.json.Genesis.Hash { |
| 107 | return fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6]) |
| 108 | } |
| 109 | if gblock.StateRoot() != t.json.Genesis.StateRoot { |
| 110 | return fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.StateRoot().Bytes()[:6], t.json.Genesis.StateRoot[:6]) |
| 111 | } |
| 112 | |
| 113 | chain, err := core.NewBlockChain(db, nil, config, dpor.NewFaker(config.Dpor, db), vm.Config{}, remoteDB, nil) |
| 114 | if err != nil { |
| 115 | return err |
| 116 | } |
| 117 | defer chain.Stop() |
| 118 | |
| 119 | validBlocks, err := t.insertBlocks(chain) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | cmlast := chain.CurrentBlock().Hash() |
| 124 | if common.Hash(t.json.BestBlock) != cmlast { |
| 125 | return fmt.Errorf("last block hash validation mismatch: want: %x, have: %x", t.json.BestBlock, cmlast) |
| 126 | } |
| 127 | newDB, err := chain.State() |
| 128 | if err != nil { |
| 129 | return err |
| 130 | } |
| 131 | if err = t.validatePostState(newDB); err != nil { |
| 132 | return fmt.Errorf("post state validation failed: %v", err) |
| 133 | } |
| 134 | return t.validateImportedHeaders(chain, validBlocks) |
| 135 | } |
| 136 | |
| 137 | func (t *BlockTest) genesis(config *configs.ChainConfig) *core.Genesis { |
| 138 | return &core.Genesis{ |
nothing calls this directly
no test coverage detected