Skip to content

Commit

Permalink
migration: Add working allowlist for Alfajores (#220)
Browse files Browse the repository at this point in the history
* migration: Simplify tests

* migration: Add working allowlist for Alfajores
  • Loading branch information
palango authored Aug 23, 2024
1 parent b25ef87 commit 9839288
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
28 changes: 27 additions & 1 deletion op-chain-ops/cmd/celo-migrate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,33 @@ var (
// Add any addresses that should be allowed to overwrite existing accounts here.
alfajoresChainId: {
// Create2Deployer
// common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"): false,
common.HexToAddress("0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"): false,

// Same code as in allocs file
// EntryPoint_v070
common.HexToAddress("0x0000000071727De22E5E9d8BAf0edAc6f37da032"): false,
// Permit2
common.HexToAddress("0x000000000022D473030F116dDEE9F6B43aC78BA3"): false,
// EntryPoint_v060
common.HexToAddress("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"): false,
// DeterministicDeploymentProxy
common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C"): false,
// SafeL2_v130
common.HexToAddress("0xfb1bffC9d739B8D520DaF37dF666da4C687191EA"): false,
// MultiSend_v130
common.HexToAddress("0x998739BFdAAdde7C933B942a68053933098f9EDa"): false,
// SenderCreator_v070
common.HexToAddress("0xEFC2c1444eBCC4Db75e7613d20C6a62fF67A167C"): false,
// SenderCreator_v060
common.HexToAddress("0x7fc98430eAEdbb6070B35B39D798725049088348"): false,
// MultiCall3
common.HexToAddress("0xcA11bde05977b3631167028862bE2a173976CA11"): false,
// Safe_v130
common.HexToAddress("0x69f4D1788e39c87893C980c06EdF4b7f686e2938"): false,
// MultiSendCallOnly_v130
common.HexToAddress("0xA1dabEF33b3B82c7814B6D82A79e50F4AC44102B"): false,
// SafeSingletonFactory
common.HexToAddress("0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7"): false,
},
}
distributionScheduleAddressMap = map[uint64]common.Address{
Expand Down
54 changes: 22 additions & 32 deletions op-chain-ops/cmd/celo-migrate/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,27 @@ import (
var (
contractCode = []byte{0x01, 0x02}
defaultBalance int64 = 123
address = common.HexToAddress("a")
)

func TestApplyAllocsToState(t *testing.T) {
tests := []struct {
name string
addr common.Address
existingAccount *types.Account
newAccount types.Account
allowlist map[common.Address]bool
balanceInAccount bool
wantErr bool
name string
existingAccount *types.Account
newAccount types.Account
allowlist map[common.Address]bool
wantErr bool
}{
{
name: "Write to empty account",
addr: common.HexToAddress("01"),
newAccount: types.Account{
Code: contractCode,
Nonce: 1,
},
balanceInAccount: false,
wantErr: false,
wantErr: false,
},
{
name: "Copy account with non-zero balance fails",
addr: common.HexToAddress("a"),
existingAccount: &types.Account{
Balance: big.NewInt(defaultBalance),
},
Expand All @@ -52,20 +48,17 @@ func TestApplyAllocsToState(t *testing.T) {
},
{
name: "Write to account with only balance should overwrite and keep balance",
addr: common.HexToAddress("a"),
existingAccount: &types.Account{
Balance: big.NewInt(defaultBalance),
},
newAccount: types.Account{
Code: contractCode,
Nonce: 5,
},
balanceInAccount: true,
wantErr: false,
wantErr: false,
},
{
name: "Write to account with existing nonce fails",
addr: common.HexToAddress("c"),
existingAccount: &types.Account{
Balance: big.NewInt(defaultBalance),
Nonce: 5,
Expand All @@ -78,7 +71,6 @@ func TestApplyAllocsToState(t *testing.T) {
},
{
name: "Write to account with contract code fails",
addr: common.HexToAddress("b"),
existingAccount: &types.Account{
Balance: big.NewInt(defaultBalance),
Code: bytes.Repeat([]byte{0x01}, 10),
Expand All @@ -91,7 +83,6 @@ func TestApplyAllocsToState(t *testing.T) {
},
{
name: "Write account with allowlist overwrites",
addr: common.HexToAddress("d"),
existingAccount: &types.Account{
Balance: big.NewInt(defaultBalance),
Code: bytes.Repeat([]byte{0x01}, 10),
Expand All @@ -100,9 +91,8 @@ func TestApplyAllocsToState(t *testing.T) {
Code: contractCode,
Nonce: 5,
},
allowlist: map[common.Address]bool{common.HexToAddress("d"): true},
balanceInAccount: true,
wantErr: false,
allowlist: map[common.Address]bool{address: true},
wantErr: false,
},
}
for _, tt := range tests {
Expand All @@ -112,20 +102,20 @@ func TestApplyAllocsToState(t *testing.T) {
sdb, _ := state.New(types.EmptyRootHash, tdb, nil)

if tt.existingAccount != nil {
sdb.CreateAccount(tt.addr)
sdb.CreateAccount(address)

if tt.existingAccount.Balance != nil {
sdb.SetBalance(tt.addr, uint256.MustFromBig(tt.existingAccount.Balance))
sdb.SetBalance(address, uint256.MustFromBig(tt.existingAccount.Balance))
}
if tt.existingAccount.Nonce != 0 {
sdb.SetNonce(tt.addr, tt.existingAccount.Nonce)
sdb.SetNonce(address, tt.existingAccount.Nonce)
}
if tt.existingAccount.Code != nil {
sdb.SetCode(tt.addr, tt.existingAccount.Code)
sdb.SetCode(address, tt.existingAccount.Code)
}
}

if err := applyAllocsToState(sdb, &core.Genesis{Alloc: types.GenesisAlloc{tt.addr: tt.newAccount}}, tt.allowlist); (err != nil) != tt.wantErr {
if err := applyAllocsToState(sdb, &core.Genesis{Alloc: types.GenesisAlloc{address: tt.newAccount}}, tt.allowlist); (err != nil) != tt.wantErr {
t.Errorf("applyAllocsToState() error = %v, wantErr %v", err, tt.wantErr)
}

Expand All @@ -134,17 +124,17 @@ func TestApplyAllocsToState(t *testing.T) {
return
}

if !sdb.Exist(tt.addr) {
t.Errorf("account does not exists as expected: %v", tt.addr.Hex())
if !sdb.Exist(address) {
t.Errorf("account does not exists as expected: %v", address.Hex())
}

assert.Equal(t, tt.newAccount.Nonce, sdb.GetNonce(tt.addr))
assert.Equal(t, tt.newAccount.Code, sdb.GetCode(tt.addr))
assert.Equal(t, tt.newAccount.Nonce, sdb.GetNonce(address))
assert.Equal(t, tt.newAccount.Code, sdb.GetCode(address))

if tt.balanceInAccount {
assert.True(t, big.NewInt(defaultBalance).Cmp(sdb.GetBalance(tt.addr).ToBig()) == 0)
if tt.existingAccount != nil {
assert.True(t, big.NewInt(defaultBalance).Cmp(sdb.GetBalance(address).ToBig()) == 0)
} else {
assert.True(t, big.NewInt(0).Cmp(sdb.GetBalance(tt.addr).ToBig()) == 0)
assert.True(t, big.NewInt(0).Cmp(sdb.GetBalance(address).ToBig()) == 0)
}
})
}
Expand Down

0 comments on commit 9839288

Please sign in to comment.