()
| 29 | ) |
| 30 | |
| 31 | func ExampleGenerateChain() { |
| 32 | var ( |
| 33 | key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") |
| 34 | key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") |
| 35 | key3, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") |
| 36 | addr1 = crypto.PubkeyToAddress(key1.PublicKey) |
| 37 | addr2 = crypto.PubkeyToAddress(key2.PublicKey) |
| 38 | addr3 = crypto.PubkeyToAddress(key3.PublicKey) |
| 39 | db = database.NewMemDatabase() |
| 40 | remoteDB = database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter()) |
| 41 | ) |
| 42 | |
| 43 | type configBackup struct { |
| 44 | Cep1LastBlockY1 *big.Int |
| 45 | Cep1LastBlockY2 *big.Int |
| 46 | Cep1LastBlockY3 *big.Int |
| 47 | Cep1LastBlockY4 *big.Int |
| 48 | Cep1LastBlockY5 *big.Int |
| 49 | } |
| 50 | bak := configBackup{ |
| 51 | Cep1LastBlockY1: configs.Cep1LastBlockY1(), |
| 52 | Cep1LastBlockY2: configs.Cep1LastBlockY2(), |
| 53 | Cep1LastBlockY3: configs.Cep1LastBlockY3(), |
| 54 | Cep1LastBlockY4: configs.Cep1LastBlockY4(), |
| 55 | Cep1LastBlockY5: configs.Cep1LastBlockY5(), |
| 56 | } |
| 57 | |
| 58 | configs.TestOnly_SetCep1LastBlockY1(big.NewInt(1)) |
| 59 | configs.TestOnly_SetCep1LastBlockY2(big.NewInt(2)) |
| 60 | configs.TestOnly_SetCep1LastBlockY3(big.NewInt(3)) |
| 61 | configs.TestOnly_SetCep1LastBlockY4(big.NewInt(4)) |
| 62 | configs.TestOnly_SetCep1LastBlockY5(big.NewInt(5)) |
| 63 | |
| 64 | // recover configs.Cep1LastBlockYx |
| 65 | defer func() { |
| 66 | configs.TestOnly_SetCep1LastBlockY1(bak.Cep1LastBlockY1) |
| 67 | configs.TestOnly_SetCep1LastBlockY2(bak.Cep1LastBlockY2) |
| 68 | configs.TestOnly_SetCep1LastBlockY3(bak.Cep1LastBlockY3) |
| 69 | configs.TestOnly_SetCep1LastBlockY4(bak.Cep1LastBlockY4) |
| 70 | configs.TestOnly_SetCep1LastBlockY5(bak.Cep1LastBlockY5) |
| 71 | |
| 72 | }() |
| 73 | |
| 74 | // Ensure that key1 has some funds in the genesis block. |
| 75 | gspec := DefaultGenesisBlock() |
| 76 | gspec.Alloc = GenesisAlloc{addr1: {Balance: big.NewInt(1000000)}} |
| 77 | // Config: &configs.ChainConfig{HomesteadBlock: new(big.Int)}, |
| 78 | genesis := gspec.MustCommit(db) |
| 79 | |
| 80 | engine := dpor.NewFaker(configs.ChainConfigInfo().Dpor, db) |
| 81 | // This call generates a chain of 5 blocks. The function runs for |
| 82 | // each block and adds different features to gen based on the |
| 83 | // block index. |
| 84 | signer := types.HomesteadSigner{} |
| 85 | n := 5 |
| 86 | chain, _ := GenerateChain(gspec.Config, genesis, engine, db, remoteDB, n, func(i int, gen *BlockGen) { |
| 87 | switch i { |
| 88 | case 0: |
nothing calls this directly
no test coverage detected