-
Notifications
You must be signed in to change notification settings - Fork 660
/
vectors_v2.go
89 lines (79 loc) · 3.15 KB
/
vectors_v2.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package vectors
import (
"github.com/0xPolygonHermez/zkevm-node/merkletree"
"github.com/0xPolygonHermez/zkevm-node/state"
)
// StateTransitionTestCaseV2 holds the metadata needed to run a state transition test
type StateTransitionTestCaseV2 struct {
Description string `json:"Description"`
Genesis []GenesisEntity `json:"genesis"`
ExpectedOldStateRoot string `json:"expectedOldStateRoot"`
ExpectedNewStateRoot string `json:"expectedNewStateRoot"`
ExpectedNewLeafs []LeafV2 `json:"expectedNewLeafs"`
Receipts []TestReceipt `json:"receipts"`
GlobalExitRoot string `json:"globalExitRoot"`
BatchL2Data string `json:"batchL2Data"`
}
// LeafV2 represents the state of a leaf in the merkle tree
type LeafV2 struct {
Address string `json:"address"`
Balance argBigInt `json:"balance"`
Nonce string `json:"nonce"`
Storage map[string]string `json:"storage"`
IsSmartContract bool `json:"isSmartContract"`
Bytecode string `json:"bytecode"`
HashBytecode string `json:"hashBytecode"`
BytecodeLength int `json:"bytecodeLength"`
}
// GenesisEntity represents the state of an account or smart contract when the network
// starts
type GenesisEntity struct {
Address string `json:"address"`
PvtKey *string `json:"pvtKey"`
Balance argBigInt `json:"balance"`
Nonce string `json:"nonce"`
Storage map[string]string `json:"storage"`
IsSmartContract bool `json:"isSmartContract"`
Bytecode *string `json:"bytecode"`
}
func GenerateGenesisActions(genesis []GenesisEntity) []*state.GenesisAction {
var genesisActions []*state.GenesisAction
for _, genesisEntity := range genesis {
if genesisEntity.Balance.String() != "0" {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeBalance),
Value: genesisEntity.Balance.String(),
}
genesisActions = append(genesisActions, action)
}
if genesisEntity.Nonce != "" && genesisEntity.Nonce != "0" {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeNonce),
Value: genesisEntity.Nonce,
}
genesisActions = append(genesisActions, action)
}
if genesisEntity.IsSmartContract && genesisEntity.Bytecode != nil && *genesisEntity.Bytecode != "0x" {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeCode),
Bytecode: *genesisEntity.Bytecode,
}
genesisActions = append(genesisActions, action)
}
if genesisEntity.IsSmartContract && len(genesisEntity.Storage) > 0 {
for storageKey, storageValue := range genesisEntity.Storage {
action := &state.GenesisAction{
Address: genesisEntity.Address,
Type: int(merkletree.LeafTypeStorage),
StoragePosition: storageKey,
Value: storageValue,
}
genesisActions = append(genesisActions, action)
}
}
}
return genesisActions
}