forked from z1labs/Cypher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArbAggregator_test.go
111 lines (89 loc) · 2.89 KB
/
ArbAggregator_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
package precompiles
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/offchainlabs/nitro/arbos/l1pricing"
)
func TestArbAggregatorBatchPosters(t *testing.T) {
evm := newMockEVMForTesting()
context := testContext(common.Address{}, evm)
addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20])
// initially should have one batch poster
bps, err := ArbAggregator{}.GetBatchPosters(context, evm)
Require(t, err)
if len(bps) != 1 {
Fail(t)
}
// add addr as a batch poster
Require(t, ArbDebug{}.BecomeChainOwner(context, evm))
Require(t, ArbAggregator{}.AddBatchPoster(context, evm, addr))
// there should now be two batch posters, and addr should be one of them
bps, err = ArbAggregator{}.GetBatchPosters(context, evm)
Require(t, err)
if len(bps) != 2 {
Fail(t)
}
if bps[0] != addr && bps[1] != addr {
Fail(t)
}
}
func TestFeeCollector(t *testing.T) {
evm := newMockEVMForTesting()
agg := ArbAggregator{}
aggAddr := l1pricing.BatchPosterAddress
collectorAddr := common.BytesToAddress(crypto.Keccak256([]byte{1})[:20])
impostorAddr := common.BytesToAddress(crypto.Keccak256([]byte{2})[:20])
aggCtx := testContext(aggAddr, evm)
callerCtx := testContext(common.Address{}, evm)
collectorCtx := testContext(collectorAddr, evm)
imposterCtx := testContext(impostorAddr, evm)
// initial result should be addr
coll, err := agg.GetFeeCollector(callerCtx, evm, aggAddr)
Require(t, err)
if coll != aggAddr {
Fail(t)
}
// set fee collector to collectorAddr
Require(t, agg.SetFeeCollector(aggCtx, evm, aggAddr, collectorAddr))
// fee collector should now be collectorAddr
coll, err = agg.GetFeeCollector(callerCtx, evm, aggAddr)
Require(t, err)
if coll != collectorAddr {
Fail(t)
}
// trying to set someone else's collector is an error
shouldErr := agg.SetFeeCollector(imposterCtx, evm, aggAddr, impostorAddr)
if shouldErr == nil {
Fail(t)
}
// but the fee collector can replace itself
Require(t, agg.SetFeeCollector(collectorCtx, evm, aggAddr, impostorAddr))
}
func TestTxBaseFee(t *testing.T) {
evm := newMockEVMForTesting()
agg := ArbAggregator{}
aggAddr := common.BytesToAddress(crypto.Keccak256([]byte{0})[:20])
targetFee := big.NewInt(973)
aggCtx := testContext(aggAddr, evm)
callerCtx := testContext(common.Address{}, evm)
// initial result should be zero
fee, err := agg.GetTxBaseFee(callerCtx, evm, aggAddr)
Require(t, err)
if fee.Cmp(big.NewInt(0)) != 0 {
Fail(t, fee)
}
// set base fee to value -- should be ignored
if err := agg.SetTxBaseFee(aggCtx, evm, aggAddr, targetFee); err != nil {
Fail(t, err)
}
// base fee should still be zero
fee, err = agg.GetTxBaseFee(callerCtx, evm, aggAddr)
Require(t, err)
if fee.Cmp(big.NewInt(0)) != 0 {
Fail(t, fee)
}
}