Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JkLondon committed Sep 10, 2024
1 parent 44e3f64 commit 8192713
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions turbo/jsonrpc/trace_adhoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func TestSwapBalance(t *testing.T) {
var latest = rpc.LatestBlockNumber
results, err := api.CallMany(context.Background(), json.RawMessage(`
[
[{"from":"0x71562b71999873db5b286df957af199ec94617f7","to":"0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b","gas":"0x5208","gasPrice":"0x1","value":"0x520A"},["trace", "stateDiff"]],
[{"from":"0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b","to":"0x71562b71999873db5b286df957af199ec94617f7","gas":"0x5208","gasPrice":"0x1","value":"0x1"},["trace", "stateDiff"]]
[{"from":"0x71562b71999873db5b286df957af199ec94617f7","to":"0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b","gas":"0x5208","gasPrice":"0x0","value":"0x2"},["trace", "stateDiff"]],
[{"from":"0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b","to":"0x71562b71999873db5b286df957af199ec94617f7","gas":"0x5208","gasPrice":"0x0","value":"0x1"},["trace", "stateDiff"]]
]
`), &rpc.BlockNumberOrHash{BlockNumber: &latest}, nil)

Expand All @@ -125,40 +125,60 @@ func TestSwapBalance(t *testing.T) {
if res, ok := results[0].StateDiff[libcommon.HexToAddress("0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b")]; !ok {
t.Errorf("don't found B in first tx")
} else {
b := res.Balance.(map[string]*hexutil.Big)
b, okConv := res.Balance.(map[string]*hexutil.Big)
if !okConv {
t.Errorf("bad interface %+v", res.Balance)
}
for i := range b {
require.Equal(t, uint64(21000+2), b[i].Uint64())
println("1st 0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b balance", b[i].Uint64())
require.Equal(t, uint64(2), b[i].Uint64())
}
}

if res, ok := results[0].StateDiff[libcommon.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")]; !ok {
t.Errorf("don't found A in first tx")
} else {
b := res.Balance.(map[string]*StateDiffBalance)
b, okConv := res.Balance.(map[string]*StateDiffBalance)
if !okConv {
t.Errorf("bad interface %+v", res.Balance)
}
for i := range b {
require.Equal(t, uint64(21000+21000+2), b[i].From.Uint64()-b[i].To.Uint64())
println("1st 0x71562b71999873db5b286df957af199ec94617f7 diff", b[i].From.Uint64(), b[i].To.Uint64())
require.Equal(t, uint64(2), b[i].From.Uint64()-b[i].To.Uint64())
}
}

if res, ok := results[1].StateDiff[libcommon.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")]; !ok {
t.Errorf("don't found A in second tx")
} else {
b := res.Balance.(map[string]*StateDiffBalance)
b, okConv := res.Balance.(map[string]*StateDiffBalance)
if !okConv {
t.Errorf("bad interface %+v", res.Balance)
}
for i := range b {
require.Equal(t, uint64(21000+21000+1), b[i].From.Uint64()-b[i].To.Uint64())
println("2nd 0x71562b71999873db5b286df957af199ec94617f7 diff", b[i].From.Uint64(), b[i].To.Uint64())
require.Equal(t, uint64(1), b[i].To.Uint64()-b[i].From.Uint64())
}
}

if res, ok := results[1].StateDiff[libcommon.HexToAddress("0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b")]; !ok {
t.Errorf("don't found B in second tx")
} else {
b := res.Balance.(map[string]*hexutil.Big)
for i := range b {
require.Equal(t, uint64(1), b[i].Uint64())
b, okConv := res.Balance.(map[string]*hexutil.Big)
if !okConv {
b := res.Balance.(map[string]*StateDiffBalance)
for i := range b {
println("2nd 0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b diff", b[i].From.Uint64(), b[i].To.Uint64())
require.Equal(t, uint64(1), b[i].From.Uint64()-b[i].To.Uint64())
}
} else {
for i := range b {
println("2nd 0x14627ea0e2B27b817DbfF94c3dA383bB73F8C30b balance", b[i].Uint64())
require.Equal(t, uint64(1), b[i].Uint64())
}
}
}
}

func TestReplayTransaction(t *testing.T) {
m, _, _ := rpcdaemontest.CreateTestSentry(t)
api := NewTraceAPI(newBaseApiForTest(m), m.DB, &httpcfg.HttpCfg{})
Expand Down

0 comments on commit 8192713

Please sign in to comment.