forked from dominant-strategies/go-quai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chain_fork_tests.go
75 lines (67 loc) · 2.34 KB
/
chain_fork_tests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package core
import (
"errors"
"math/big"
"github.com/spruce-solutions/go-quai/common"
"github.com/spruce-solutions/go-quai/core/types"
)
// Generate blocks to form a network of chains
func SendNetworkBlocksToNode(graph [3][3][]*blockGenSpec, blocks []*types.Block) error {
return errors.New("Not implemented")
}
func GetNodeHeadAndTD() (common.Hash, [3]*big.Int, error) {
return common.Hash{}, [3]*big.Int{}, errors.New("Not implemented")
}
// Example test for a fork choice scenario shown in slide00 (not a real slide)
func ForkChoiceTest_Slide00() {
// Define the network graph here
graph := [3][3][]*blockGenSpec{
{ // Region0
{ // Zone0
&blockGenSpec{[3]int{1, 1, 1}, [3]string{}, "z00_1"},
&blockGenSpec{[3]int{-1, -1, 2}, [3]string{}, ""},
// ...
&blockGenSpec{[3]int{-1, 2, 4}, [3]string{}, "z00_4"},
&blockGenSpec{[3]int{3, 3, 5}, [3]string{}, ""},
&blockGenSpec{[3]int{-1, -1, 6}, [3]string{}, ""}, // END OF CANONICAL CHAIN
&blockGenSpec{[3]int{-1, -1, 5}, [3]string{"", "", "z00_4"}, ""}, // Fork at z00_4
// ...
&blockGenSpec{[3]int{-1, 3, 8}, [3]string{}, ""},
&blockGenSpec{[3]int{-1, -1, 5}, [3]string{"", "", "z00_4"}, ""}, // Fork at z00_4
&blockGenSpec{[3]int{-1, -1, 6}, [3]string{}, ""},
&blockGenSpec{[3]int{-1, -1, 7}, [3]string{"", "z00_1", ""}, ""}, // Twist to z00_1
},
{}, // ... Zone1 omitted
{}, // ... Zone2 omitted
},
{ // Region1
{ // Zone0
&blockGenSpec{[3]int{1, 1, 2}, [3]string{"", "", "z00_1"}, ""},
},
{}, // ... Zone1 omitted
{}, // ... Zone2 omitted
},
{}, // ... Region2 omitted
}
// Generate the blocks for this graph
blocks, err := GenerateNetworkBlocks(graph)
if err != nil {
panic("Error generating blocks!")
}
// Send internal & external blocks to the node
err = SendNetworkBlocksToNode(graph, blocks)
if err != nil {
panic("Failed to send all blocks to the node!")
}
// Confirm the node arrived at the expected head, with the expected total difficulty
expectedHead := common.Hash{}
expectedTD := [3]*big.Int{big.NewInt(0), big.NewInt(0), big.NewInt(0)}
head, td, err := GetNodeHeadAndTD()
if err != nil {
panic("Error getting node head & total difficulty!")
} else if head != expectedHead {
panic("Node is on the wrong head!")
} else if td != expectedTD {
panic("Node has the wrong total difficulty!")
}
}