Merge pull request #644 from gzliudan/format-0x

all: change format 0x%x to %#x
This commit is contained in:
Daniel Liu 2024-10-17 10:35:34 +08:00 committed by GitHub
commit a8ea86e40c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 831 additions and 29 deletions

View file

@ -76,7 +76,7 @@ func runCmd(ctx *cli.Context) error {
log.Root().SetHandler(glogger) log.Root().SetHandler(glogger)
logconfig := &vm.LogConfig{ logconfig := &vm.LogConfig{
EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name), EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name),
DisableStack: ctx.GlobalBool(DisableStackFlag.Name), DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
} }
var ( var (
@ -238,7 +238,7 @@ Gas used: %d
if tracer != nil { if tracer != nil {
tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime, err) tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime, err)
} else { } else {
fmt.Printf("0x%x\n", ret) fmt.Printf("%#x\n", ret)
if err != nil { if err != nil {
fmt.Printf(" error: %v\n", err) fmt.Printf(" error: %v\n", err)
} }

View file

@ -35,7 +35,7 @@ func VerifyForkHashes(config *params.ChainConfig, header *types.Header, uncle bo
// If the homestead reprice hash is set, validate it // If the homestead reprice hash is set, validate it
if config.EIP150Block != nil && config.EIP150Block.Cmp(header.Number) == 0 { if config.EIP150Block != nil && config.EIP150Block.Cmp(header.Number) == 0 {
if config.EIP150Hash != (common.Hash{}) && config.EIP150Hash != header.Hash() { if config.EIP150Hash != (common.Hash{}) && config.EIP150Hash != header.Hash() {
return fmt.Errorf("homestead gas reprice fork: have 0x%x, want 0x%x", header.Hash(), config.EIP150Hash) return fmt.Errorf("homestead gas reprice fork: have %#x, want %#x", header.Hash(), config.EIP150Hash)
} }
} }
// All ok, return // All ok, return

View file

@ -109,7 +109,7 @@ func PrintDisassembled(code string) error {
it := NewInstructionIterator(script) it := NewInstructionIterator(script)
for it.Next() { for it.Next() {
if it.Arg() != nil && 0 < len(it.Arg()) { if it.Arg() != nil && 0 < len(it.Arg()) {
fmt.Printf("%06v: %v 0x%x\n", it.PC(), it.Op(), it.Arg()) fmt.Printf("%06v: %v %#x\n", it.PC(), it.Op(), it.Arg())
} else { } else {
fmt.Printf("%06v: %v\n", it.PC(), it.Op()) fmt.Printf("%06v: %v\n", it.PC(), it.Op())
} }
@ -124,7 +124,7 @@ func Disassemble(script []byte) ([]string, error) {
it := NewInstructionIterator(script) it := NewInstructionIterator(script)
for it.Next() { for it.Next() {
if it.Arg() != nil && 0 < len(it.Arg()) { if it.Arg() != nil && 0 < len(it.Arg()) {
instrs = append(instrs, fmt.Sprintf("%06v: %v 0x%x\n", it.PC(), it.Op(), it.Arg())) instrs = append(instrs, fmt.Sprintf("%06v: %v %#x\n", it.PC(), it.Op(), it.Arg()))
} else { } else {
instrs = append(instrs, fmt.Sprintf("%06v: %v\n", it.PC(), it.Op())) instrs = append(instrs, fmt.Sprintf("%06v: %v\n", it.PC(), it.Op()))
} }

View file

@ -2365,7 +2365,7 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e
Chain config: %v Chain config: %v
Number: %v Number: %v
Hash: 0x%x Hash: %#x
%v %v
Round: %v Round: %v

View file

@ -539,7 +539,7 @@ func (tx *Transaction) String() string {
GasPrice: %#x GasPrice: %#x
GasLimit %#x GasLimit %#x
Value: %#x Value: %#x
Data: 0x%x Data: %#x
V: %#x V: %#x
R: %#x R: %#x
S: %#x S: %#x

View file

@ -654,7 +654,7 @@ func TestCreate2Addreses(t *testing.T) {
stack.push(big.NewInt(0)) // memstart stack.push(big.NewInt(0)) // memstart
stack.push(big.NewInt(0)) // value stack.push(big.NewInt(0)) // value
gas, _ := gasCreate2(params.GasTable{}, nil, nil, stack, nil, 0) gas, _ := gasCreate2(params.GasTable{}, nil, nil, stack, nil, 0)
fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* init_code `0x%x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String()) fmt.Printf("Example %d\n* address `%#x`\n* salt `%#x`\n* init_code `%#x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String())
*/ */
expected := common.BytesToAddress(common.FromHex(tt.expected)) expected := common.BytesToAddress(common.FromHex(tt.expected))
if !bytes.Equal(expected.Bytes(), address.Bytes()) { if !bytes.Equal(expected.Bytes(), address.Bytes()) {

View file

@ -220,7 +220,7 @@ func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration
l.output = output l.output = output
l.err = err l.err = err
if l.cfg.Debug { if l.cfg.Debug {
fmt.Printf("0x%x\n", output) fmt.Printf("%#x\n", output)
if err != nil { if err != nil {
fmt.Printf(" error: %v\n", err) fmt.Printf(" error: %v\n", err)
} }
@ -305,11 +305,11 @@ func NewMarkdownLogger(cfg *LogConfig, writer io.Writer) *mdLogger {
func (t *mdLogger) CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) { func (t *mdLogger) CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
if !create { if !create {
fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `0x%x`\nGas: `%d`\nValue `%v` wei\n", fmt.Fprintf(t.out, "From: `%v`\nTo: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
from.String(), to.String(), from.String(), to.String(),
input, gas, value) input, gas, value)
} else { } else {
fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `0x%x`\nGas: `%d`\nValue `%v` wei\n", fmt.Fprintf(t.out, "From: `%v`\nCreate at: `%v`\nData: `%#x`\nGas: `%d`\nValue `%v` wei\n",
from.String(), to.String(), from.String(), to.String(),
input, gas, value) input, gas, value)
} }
@ -346,7 +346,7 @@ func (t *mdLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64
} }
func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) { func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) {
fmt.Fprintf(t.out, "\nOutput: `0x%x`\nConsumed gas: `%d`\nError: `%v`\n", fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
output, gasUsed, err) output, gasUsed, err)
} }

View file

@ -498,7 +498,7 @@ func TestEip2929Cases(t *testing.T) {
it := asm.NewInstructionIterator(code) it := asm.NewInstructionIterator(code)
for it.Next() { for it.Next() {
if it.Arg() != nil && 0 < len(it.Arg()) { if it.Arg() != nil && 0 < len(it.Arg()) {
instrs = append(instrs, fmt.Sprintf("%v 0x%x", it.Op(), it.Arg())) instrs = append(instrs, fmt.Sprintf("%v %#x", it.Op(), it.Arg()))
} else { } else {
instrs = append(instrs, fmt.Sprintf("%v", it.Op())) instrs = append(instrs, fmt.Sprintf("%v", it.Op()))
} }
@ -506,7 +506,7 @@ func TestEip2929Cases(t *testing.T) {
ops := strings.Join(instrs, ", ") ops := strings.Join(instrs, ", ")
fmt.Printf("### Case %d\n\n", id) fmt.Printf("### Case %d\n\n", id)
id++ id++
fmt.Printf("%v\n\nBytecode: \n```\n0x%x\n```\nOperations: \n```\n%v\n```\n\n", fmt.Printf("%v\n\nBytecode: \n```\n%#x\n```\nOperations: \n```\n%v\n```\n\n",
comment, comment,
code, ops) code, ops)
Execute(code, nil, &Config{ Execute(code, nil, &Config{

View file

@ -17,10 +17,11 @@
package eth package eth
import ( import (
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"reflect" "reflect"
"testing" "testing"
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core/state" "github.com/XinFinOrg/XDPoSChain/core/state"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
@ -84,7 +85,7 @@ func TestStorageRangeAt(t *testing.T) {
t.Error(err) t.Error(err)
} }
if !reflect.DeepEqual(result, test.want) { if !reflect.DeepEqual(result, test.want) {
t.Fatalf("wrong result for range 0x%x.., limit %d:\ngot %s\nwant %s", t.Fatalf("wrong result for range %#x.., limit %d:\ngot %s\nwant %s",
test.start, test.limit, dumper.Sdump(result), dumper.Sdump(&test.want)) test.start, test.limit, dumper.Sdump(result), dumper.Sdump(&test.want))
} }
} }

View file

@ -56,7 +56,7 @@ func TestUnmarshalJSONNewFilterArgs(t *testing.T) {
// from, to block number // from, to block number
var test1 FilterCriteria var test1 FilterCriteria
vector := fmt.Sprintf(`{"fromBlock":"0x%x","toBlock":"0x%x"}`, fromBlock, toBlock) vector := fmt.Sprintf(`{"fromBlock":"%#x","toBlock":"%#x"}`, fromBlock, toBlock)
if err := json.Unmarshal([]byte(vector), &test1); err != nil { if err := json.Unmarshal([]byte(vector), &test1); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -3333,7 +3333,7 @@ func (api *PublicDebugAPI) SeedHash(ctx context.Context, number uint64) (string,
if block == nil { if block == nil {
return "", fmt.Errorf("block #%d not found", number) return "", fmt.Errorf("block #%d not found", number)
} }
return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil return fmt.Sprintf("%#x", ethash.SeedHash(number)), nil
} }
// PrivateDebugAPI is the collection of Ethereum APIs exposed over the private // PrivateDebugAPI is the collection of Ethereum APIs exposed over the private

View file

@ -41,7 +41,7 @@ func (n *Nonce) GetBytes() []byte {
// GetHex retrieves the hex string representation of the block nonce. // GetHex retrieves the hex string representation of the block nonce.
func (n *Nonce) GetHex() string { func (n *Nonce) GetHex() string {
return fmt.Sprintf("0x%x", n.nonce[:]) return fmt.Sprintf("%#x", n.nonce[:])
} }
// Bloom represents a 256 bit bloom filter. // Bloom represents a 256 bit bloom filter.
@ -56,7 +56,7 @@ func (b *Bloom) GetBytes() []byte {
// GetHex retrieves the hex string representation of the bloom filter. // GetHex retrieves the hex string representation of the bloom filter.
func (b *Bloom) GetHex() string { func (b *Bloom) GetHex() string {
return fmt.Sprintf("0x%x", b.bloom[:]) return fmt.Sprintf("%#x", b.bloom[:])
} }
// Header represents a block header in the Ethereum blockchain. // Header represents a block header in the Ethereum blockchain.

View file

@ -56,14 +56,14 @@ var nodeDBKeyTests = []struct {
func TestNodeDBKeys(t *testing.T) { func TestNodeDBKeys(t *testing.T) {
for i, tt := range nodeDBKeyTests { for i, tt := range nodeDBKeyTests {
if key := makeKey(tt.id, tt.field); !bytes.Equal(key, tt.key) { if key := makeKey(tt.id, tt.field); !bytes.Equal(key, tt.key) {
t.Errorf("make test %d: key mismatch: have 0x%x, want 0x%x", i, key, tt.key) t.Errorf("make test %d: key mismatch: have %#x, want %#x", i, key, tt.key)
} }
id, field := splitKey(tt.key) id, field := splitKey(tt.key)
if !bytes.Equal(id[:], tt.id[:]) { if !bytes.Equal(id[:], tt.id[:]) {
t.Errorf("split test %d: id mismatch: have 0x%x, want 0x%x", i, id, tt.id) t.Errorf("split test %d: id mismatch: have %#x, want %#x", i, id, tt.id)
} }
if field != tt.field { if field != tt.field {
t.Errorf("split test %d: field mismatch: have 0x%x, want 0x%x", i, field, tt.field) t.Errorf("split test %d: field mismatch: have %#x, want %#x", i, field, tt.field)
} }
} }
} }

View file

@ -56,14 +56,14 @@ var nodeDBKeyTests = []struct {
func TestNodeDBKeys(t *testing.T) { func TestNodeDBKeys(t *testing.T) {
for i, tt := range nodeDBKeyTests { for i, tt := range nodeDBKeyTests {
if key := makeKey(tt.id, tt.field); !bytes.Equal(key, tt.key) { if key := makeKey(tt.id, tt.field); !bytes.Equal(key, tt.key) {
t.Errorf("make test %d: key mismatch: have 0x%x, want 0x%x", i, key, tt.key) t.Errorf("make test %d: key mismatch: have %#x, want %#x", i, key, tt.key)
} }
id, field := splitKey(tt.key) id, field := splitKey(tt.key)
if !bytes.Equal(id[:], tt.id[:]) { if !bytes.Equal(id[:], tt.id[:]) {
t.Errorf("split test %d: id mismatch: have 0x%x, want 0x%x", i, id, tt.id) t.Errorf("split test %d: id mismatch: have %#x, want %#x", i, id, tt.id)
} }
if field != tt.field { if field != tt.field {
t.Errorf("split test %d: field mismatch: have 0x%x, want 0x%x", i, field, tt.field) t.Errorf("split test %d: field mismatch: have %#x, want %#x", i, field, tt.field)
} }
} }
} }

View file

@ -440,7 +440,7 @@ func (op ptrOp) genWrite(ctx *genContext, v string) string {
var b bytes.Buffer var b bytes.Buffer
fmt.Fprintf(&b, "if %s == nil {\n", v) fmt.Fprintf(&b, "if %s == nil {\n", v)
fmt.Fprintf(&b, " w.Write([]byte{0x%X})\n", op.nilValue) fmt.Fprintf(&b, " w.Write([]byte{%#X})\n", op.nilValue)
fmt.Fprintf(&b, "} else {\n") fmt.Fprintf(&b, "} else {\n")
fmt.Fprintf(&b, " %s", op.elem.genWrite(ctx, vv)) fmt.Fprintf(&b, " %s", op.elem.genWrite(ctx, vv))
fmt.Fprintf(&b, "}\n") fmt.Fprintf(&b, "}\n")

801
test.txt Normal file

File diff suppressed because one or more lines are too long

View file

@ -88,6 +88,6 @@ func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
} else { } else {
t.Log("EVM operation log:\n" + buf.String()) t.Log("EVM operation log:\n" + buf.String())
} }
t.Logf("EVM output: 0x%x", tracer.Output()) t.Logf("EVM output: %#x", tracer.Output())
t.Logf("EVM error: %v", tracer.Error()) t.Logf("EVM error: %v", tracer.Error())
} }

View file

@ -422,7 +422,7 @@ func runRandTest(rt randTest) bool {
v := tr.Get(step.key) v := tr.Get(step.key)
want := values[string(step.key)] want := values[string(step.key)]
if string(v) != want { if string(v) != want {
rt[i].err = fmt.Errorf("mismatch for key 0x%x, got 0x%x want 0x%x", step.key, v, want) rt[i].err = fmt.Errorf("mismatch for key %#x, got %#x want %#x", step.key, v, want)
} }
case opCommit: case opCommit:
_, rt[i].err = tr.Commit(nil) _, rt[i].err = tr.Commit(nil)