forked from vechain/thor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage for tracers (vechain#670)
* Increase coverage for tracers * Replace mockHash with BytesToHash * small tweak --------- Co-authored-by: tony <[email protected]>
- Loading branch information
1 parent
85d1b30
commit 1ba1783
Showing
2 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package logger | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/vechain/thor/v2/vm" | ||
) | ||
|
||
// Implement the StateDB interface partially for testing | ||
type mockStateDB struct { | ||
vm.StateDB | ||
refund uint64 | ||
} | ||
|
||
func (m *mockStateDB) GetRefund() uint64 { | ||
return m.refund | ||
} | ||
|
||
func TestJSONLogger(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
logger := NewJSONLogger(nil, &buf) | ||
env := &vm.EVM{} | ||
stateDB := &mockStateDB{refund: 100} | ||
env.StateDB = stateDB | ||
|
||
logger.CaptureStart(env, common.Address{}, common.Address{}, false, nil, 0, big.NewInt(0)) | ||
|
||
memory := vm.NewMemory() | ||
stack := &vm.Stack{} | ||
contract := vm.NewContract(vm.AccountRef(common.Address{}), vm.AccountRef(common.Address{}), big.NewInt(0), 0) | ||
|
||
logger.CaptureState(0, vm.ADD, 10, 2, memory, stack, contract, nil, 1, nil) | ||
logger.CaptureEnd(nil, 0, nil) | ||
|
||
var logs []json.RawMessage | ||
decoder := json.NewDecoder(&buf) | ||
for { | ||
var log json.RawMessage | ||
if err := decoder.Decode(&log); err == io.EOF { | ||
break | ||
} else if err != nil { | ||
t.Fatalf("Failed to decode log: %v", err) | ||
} | ||
logs = append(logs, log) | ||
} | ||
|
||
if len(logs) != 2 { | ||
t.Errorf("Expected 2 logs, got %d", len(logs)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters