forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathgenesis_deploy_test.go
More file actions
76 lines (67 loc) · 2.24 KB
/
Copy pathgenesis_deploy_test.go
File metadata and controls
76 lines (67 loc) · 2.24 KB
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
76
package main
import (
"bufio"
"os"
"path/filepath"
"strings"
"testing"
"github.com/XinFinOrg/XDPoSChain/common"
)
// TestMakeGenesisDeploysSystemContracts runs the full makeGenesis flow via the
// non-interactive input-file path and asserts that every XDC system contract is
// deployed with real bytecode (not just a balance). This is a regression test for
// the puppeth bug where all contract deployments failed silently, producing a
// genesis with balances but no contract code/storage.
func TestMakeGenesisDeploysSystemContracts(t *testing.T) {
dir := t.TempDir()
inPath := filepath.Join(dir, "input.yaml")
outPath := filepath.Join(dir, "out.json")
const inputYAML = `name: xdc-test
chainid: 19420
epoch: 900
masternodesowner: "0xa4477b9b3dcfffb71db9e2aba579975ac756dade"
masternodes:
- "0x7e7d7b438abd152af3753bdc01512d2208305397"
- "0xd3350aaba9e8468e263eb7d197d6805b20e2918f"
- "0xdb6552adc538e39b4f2a58aea3cd365def1be89b"
stakingthreshold: 10000000
`
if err := os.WriteFile(inPath, []byte(inputYAML), 0644); err != nil {
t.Fatal(err)
}
w := &wizard{
network: "xdc-test",
in: bufio.NewReader(strings.NewReader("")),
}
w.conf.path = outPath
w.conf.inpath = inPath
w.makeGenesis()
g := w.conf.Genesis
if g == nil {
t.Fatal("makeGenesis produced no genesis")
}
systemContracts := map[string]common.Address{
"MasternodeVotingSMC (0x88)": common.MasternodeVotingSMCBinary,
"FoundationMultiSig (0x68)": common.FoundationAddrBinary,
"BlockSigners (0x89)": common.BlockSignersBinary,
"Randomize (0x90)": common.RandomizeSMCBinary,
"TeamMultiSig (0x99)": common.TeamAddrBinary,
}
for name, addr := range systemContracts {
acc, ok := g.Alloc[addr]
if !ok {
t.Errorf("%s: not present in alloc", name)
continue
}
if len(acc.Code) == 0 {
t.Errorf("%s: empty code (deployment failed silently)", name)
continue
}
t.Logf("%s: codeLen=%d storageEntries=%d", name, len(acc.Code), len(acc.Storage))
}
// The validator contract must carry candidate storage, otherwise the chain
// has no masternode set to read at the first epoch switch.
if v := g.Alloc[common.MasternodeVotingSMCBinary]; len(v.Storage) == 0 {
t.Error("MasternodeVotingSMC has no storage (no candidates registered)")
}
}