forked from omni-network/omni
-
Notifications
You must be signed in to change notification settings - Fork 1
/
allocs_test.go
69 lines (53 loc) · 1.94 KB
/
allocs_test.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
package allocs_test
import (
"encoding/json"
"math/big"
"testing"
"github.com/omni-network/omni/contracts/allocs"
"github.com/omni-network/omni/halo/genutil/evm"
"github.com/omni-network/omni/lib/netconf"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/stretchr/testify/require"
)
// TestIsLocked ensures that if a persistent network has it's genesis
// set in lib/netconf/static.go, then the allocs are locked in contracts/allocs.
func TestIsLocked(t *testing.T) {
t.Parallel()
for _, network := range netconf.All() {
if network.IsEphemeral() {
continue
}
if network.Static().ExecutionGenesisJSON == nil {
continue
}
require.True(t, allocs.IsLocked(network), "allocs should be locked for %s", network)
locked := allocs.MustAlloc(network)
var genesis core.Genesis
err := json.Unmarshal(network.Static().ExecutionGenesisJSON, &genesis)
require.NoError(t, err)
precompile := evm.PrecompilesAlloc()
prefund, err := evm.PrefundAlloc(network)
require.NoError(t, err)
for addr, acc := range genesis.Alloc {
if _, ok := precompile[addr]; ok {
continue
}
if _, ok := prefund[addr]; ok {
continue
}
lockedAcc, ok := locked[addr]
require.True(t, ok, "missing locked alloc for %s", addr)
require.Equal(t, hexBytes(acc.Code), hexBytes(lockedAcc.Code), "code mismatch for %s", addr)
require.Equal(t, hexBig(acc.Balance), hexBig(lockedAcc.Balance), "balance mismatch for %s", addr)
require.Equal(t, acc.Nonce, lockedAcc.Nonce, "nonce mismatch for %s", addr)
for key, val := range acc.Storage {
lockedVal, ok := lockedAcc.Storage[key]
require.True(t, ok, "missing storage key %s for %s", key, addr)
require.Equal(t, hexBytes(val[:]), hexBytes(lockedVal[:]), "storage mismatch for %s[%s]", addr, key)
}
}
}
}
func hexBytes(b []byte) string { return hexutil.Encode(b) }
func hexBig(b *big.Int) string { return hexutil.EncodeBig(b) }