mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
supply test compares output as JSON
This commit is contained in:
parent
a2639b2fde
commit
dec5d3b6d1
1 changed files with 24 additions and 22 deletions
|
|
@ -18,13 +18,13 @@ package tracetest
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
|
@ -92,9 +92,7 @@ func TestSupplyGenesisAlloc(t *testing.T) {
|
|||
|
||||
actual := out[expected.Number]
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSupplyRewards(t *testing.T) {
|
||||
|
|
@ -123,9 +121,7 @@ func TestSupplyRewards(t *testing.T) {
|
|||
|
||||
actual := out[expected.Number]
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSupplyEip1559Burn(t *testing.T) {
|
||||
|
|
@ -185,9 +181,7 @@ func TestSupplyEip1559Burn(t *testing.T) {
|
|||
)
|
||||
|
||||
actual := out[expected.Number]
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSupplyWithdrawals(t *testing.T) {
|
||||
|
|
@ -227,9 +221,7 @@ func TestSupplyWithdrawals(t *testing.T) {
|
|||
actual = out[expected.Number]
|
||||
)
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
}
|
||||
|
||||
// Tests fund retrieval after contract's selfdestruct.
|
||||
|
|
@ -325,9 +317,7 @@ func TestSupplySelfdestruct(t *testing.T) {
|
|||
|
||||
actual := preCancunOutput[expected.Number]
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("Pre-cancun incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
|
||||
// 2. Test post Cancun
|
||||
cancunTime := uint64(0)
|
||||
|
|
@ -368,9 +358,7 @@ func TestSupplySelfdestruct(t *testing.T) {
|
|||
|
||||
actual = postCancunOutput[expected.Number]
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("Post-cancun incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
}
|
||||
|
||||
// Tests selfdestructing contract to send its balance to itself (burn).
|
||||
|
|
@ -518,9 +506,7 @@ func TestSupplySelfdestructItselfAndRevert(t *testing.T) {
|
|||
|
||||
actual := output[expected.Number]
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Fatalf("incorrect supply info: expected %+v, got %+v", expected, actual)
|
||||
}
|
||||
compareAsJSON(t, expected, actual)
|
||||
}
|
||||
|
||||
func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockGen)) ([]supplyInfo, *core.BlockChain, error) {
|
||||
|
|
@ -575,3 +561,19 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
|
|||
|
||||
return output, chain, nil
|
||||
}
|
||||
|
||||
func compareAsJSON(t *testing.T, expected interface{}, actual interface{}) {
|
||||
want, err := json.Marshal(expected)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal expected value to JSON: %v", err)
|
||||
}
|
||||
|
||||
have, err := json.Marshal(actual)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to marshal actual value to JSON: %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(want, have) {
|
||||
t.Fatalf("incorrect supply info: expected %s, got %s", string(want), string(have))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue