forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc_test.go
More file actions
90 lines (73 loc) · 2.39 KB
/
rpc_test.go
File metadata and controls
90 lines (73 loc) · 2.39 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package txmgr
import (
"fmt"
"math/big"
"testing"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
)
func TestTxmgrRPC(t *testing.T) {
minBaseFeeInit := big.NewInt(2000)
minPriorityFeeInit := big.NewInt(1000)
minBlobFeeInit := big.NewInt(3000)
feeThresholdInit := big.NewInt(4000)
rebroadcastIntervalInit := int64(25)
bumpFeeRetryTimeInit := int64(100)
cfg := configWithNumConfs(1)
cfg.MinBaseFee.Store(minBaseFeeInit)
cfg.MinTipCap.Store(minPriorityFeeInit)
cfg.MinBlobTxFee.Store(minBlobFeeInit)
cfg.FeeLimitThreshold.Store(feeThresholdInit)
cfg.RebroadcastInterval.Store(rebroadcastIntervalInit)
cfg.ResubmissionTimeout.Store(bumpFeeRetryTimeInit)
h := newTestHarnessWithConfig(t, cfg)
appVersion := "test"
server := oprpc.NewServer(
"127.0.0.1",
0,
appVersion,
)
server.AddAPI(h.mgr.API())
require.NoError(t, server.Start())
defer func() {
_ = server.Stop()
}()
rpcClient, err := rpc.Dial(fmt.Sprintf("http://%s", server.Endpoint()))
require.NoError(t, err)
type tcase struct {
rpcMethod string
initValue *big.Int
}
cases := []tcase{
{"MinBaseFee", minBaseFeeInit},
{"MinPriorityFee", minPriorityFeeInit},
{"MinBlobFee", minBlobFeeInit},
{"FeeThreshold", feeThresholdInit},
{"RebroadcastInterval", big.NewInt(rebroadcastIntervalInit)},
{"BumpFeeRetryTime", big.NewInt(bumpFeeRetryTimeInit)},
}
for _, tc := range cases {
t.Run("Get|Set"+tc.rpcMethod, func(t *testing.T) {
var res *big.Int
require.NoError(t, rpcClient.Call(&res, "txmgr_get"+tc.rpcMethod))
require.Equal(t, tc.initValue, res)
newVal := new(big.Int)
newVal.Add(tc.initValue, big.NewInt(1))
require.NoError(t, rpcClient.Call(&res, "txmgr_set"+tc.rpcMethod, newVal))
require.NoError(t, rpcClient.Call(&res, "txmgr_get"+tc.rpcMethod))
require.Equal(t, newVal, res)
})
}
t.Run("Get|SetBlobTipCapDynamic", func(t *testing.T) {
var res bool
require.NoError(t, rpcClient.Call(&res, "txmgr_getBlobTipCapDynamic"))
require.False(t, res)
require.NoError(t, rpcClient.Call(nil, "txmgr_setBlobTipCapDynamic", true))
require.NoError(t, rpcClient.Call(&res, "txmgr_getBlobTipCapDynamic"))
require.True(t, res)
require.NoError(t, rpcClient.Call(nil, "txmgr_setBlobTipCapDynamic", false))
require.NoError(t, rpcClient.Call(&res, "txmgr_getBlobTipCapDynamic"))
require.False(t, res)
})
}