fix journal cur rev Id
This commit is contained in:
parent
1a64297b1d
commit
1862333296
|
@ -38,7 +38,7 @@ type journal struct {
|
|||
|
||||
validRevisions []revision
|
||||
nextRevisionId int
|
||||
curRevisionId int
|
||||
revIds []int
|
||||
}
|
||||
|
||||
type entry interface {
|
||||
|
@ -194,17 +194,18 @@ func (j *journal) OnTxEnd(receipt *types.Receipt, err error) {
|
|||
}
|
||||
|
||||
func (j *journal) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
|
||||
j.curRevisionId = j.snapshot()
|
||||
j.revIds = append(j.revIds, j.snapshot())
|
||||
if j.hooks != nil && j.hooks.OnEnter != nil {
|
||||
j.hooks.OnEnter(depth, typ, from, to, input, gas, value)
|
||||
}
|
||||
}
|
||||
|
||||
func (j *journal) OnExit(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
|
||||
revId := j.revIds[len(j.revIds)-1]
|
||||
j.revIds = j.revIds[:len(j.revIds)-1]
|
||||
if reverted {
|
||||
j.revertToSnapshot(j.curRevisionId, j.hooks)
|
||||
j.revertToSnapshot(revId, j.hooks)
|
||||
}
|
||||
j.curRevisionId--
|
||||
if j.hooks != nil && j.hooks.OnExit != nil {
|
||||
j.hooks.OnExit(depth, output, gasUsed, err, reverted)
|
||||
}
|
||||
|
|
|
@ -96,3 +96,31 @@ func TestJournalTopRevert(t *testing.T) {
|
|||
t.Fatalf("unexpected nonce: %v", tr.nonce)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJournalNestedCalls(t *testing.T) {
|
||||
tr := &testTracer{}
|
||||
wr, err := WrapWithJournal(&Hooks{OnBalanceChange: tr.OnBalanceChange, OnNonceChange: tr.OnNonceChange})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to wrap test tracer: %v", err)
|
||||
}
|
||||
addr := common.HexToAddress("0x1234")
|
||||
wr.OnEnter(0, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnEnter(1, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnBalanceChange(addr, big.NewInt(0), big.NewInt(100), BalanceChangeUnspecified)
|
||||
wr.OnEnter(2, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnExit(2, nil, 100, nil, false)
|
||||
wr.OnEnter(2, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnExit(2, nil, 100, nil, false)
|
||||
wr.OnEnter(2, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnBalanceChange(addr, big.NewInt(100), big.NewInt(200), BalanceChangeUnspecified)
|
||||
wr.OnExit(2, nil, 100, nil, false)
|
||||
wr.OnEnter(2, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnExit(2, nil, 100, errors.New("revert"), true)
|
||||
wr.OnEnter(2, 0, addr, addr, nil, 1000, big.NewInt(0))
|
||||
wr.OnExit(2, nil, 100, errors.New("revert"), true)
|
||||
wr.OnExit(1, nil, 100, errors.New("revert"), true)
|
||||
wr.OnExit(0, nil, 150, nil, false)
|
||||
if tr.bal.Cmp(big.NewInt(0)) != 0 {
|
||||
t.Fatalf("unexpected balance: %v", tr.bal)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue