formats the code by go fmt

This commit is contained in:
sina haseli 2024-12-14 00:19:46 +03:30
parent 99c60ebb9c
commit dad7d109a6
1 changed files with 106 additions and 106 deletions

View File

@ -939,122 +939,122 @@ func TestStandardTraceBadBlockToFile(t *testing.T) {
} }
func TestIntermediateRoots(t *testing.T) { func TestIntermediateRoots(t *testing.T) {
t.Parallel() t.Parallel()
// Setup a test backend with valid transactions // Setup a test backend with valid transactions
accounts := newAccounts(2) accounts := newAccounts(2)
genesis := &core.Genesis{ genesis := &core.Genesis{
Config: params.TestChainConfig, Config: params.TestChainConfig,
Alloc: types.GenesisAlloc{ Alloc: types.GenesisAlloc{
accounts[0].addr: {Balance: big.NewInt(params.Ether)}, accounts[0].addr: {Balance: big.NewInt(params.Ether)},
}, },
} }
signer := types.HomesteadSigner{} signer := types.HomesteadSigner{}
var badBlockHash, genesisHash common.Hash var badBlockHash, genesisHash common.Hash
backend := newTestBackend(t, 2, genesis, func(i int, b *core.BlockGen) { backend := newTestBackend(t, 2, genesis, func(i int, b *core.BlockGen) {
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{ tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: uint64(i), Nonce: uint64(i),
To: &accounts[1].addr, To: &accounts[1].addr,
Value: big.NewInt(1000), Value: big.NewInt(1000),
Gas: params.TxGas, Gas: params.TxGas,
GasPrice: b.BaseFee(), GasPrice: b.BaseFee(),
Data: nil, Data: nil,
}), signer, accounts[0].key) }), signer, accounts[0].key)
b.AddTx(tx) b.AddTx(tx)
}) })
defer backend.teardown() defer backend.teardown()
// Fetch a valid block and store its hash // Fetch a valid block and store its hash
validBlock := backend.chain.GetBlockByNumber(1) validBlock := backend.chain.GetBlockByNumber(1)
if validBlock == nil { if validBlock == nil {
t.Fatalf("failed to fetch block 1") t.Fatalf("failed to fetch block 1")
} }
// validBlockHash = validBlock.Hash() // validBlockHash = validBlock.Hash()
// Corrupt the valid block to create a bad block // Corrupt the valid block to create a bad block
badBlock := backend.chain.GetBlockByNumber(1) badBlock := backend.chain.GetBlockByNumber(1)
badBlock.Header().ParentHash = common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") badBlock.Header().ParentHash = common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")
badBlockHash = badBlock.Hash() badBlockHash = badBlock.Hash()
rawdb.WriteBadBlock(backend.chaindb, badBlock) rawdb.WriteBadBlock(backend.chaindb, badBlock)
// Add the genesis block for testing // Add the genesis block for testing
genesisBlock := backend.chain.GetBlockByNumber(0) genesisBlock := backend.chain.GetBlockByNumber(0)
genesisHash = genesisBlock.Hash() genesisHash = genesisBlock.Hash()
// Test cases // Test cases
api := NewAPI(backend) api := NewAPI(backend)
var testCases = []struct { var testCases = []struct {
name string name string
hash common.Hash hash common.Hash
config *TraceConfig config *TraceConfig
expectErr bool expectErr bool
expectMsg string expectMsg string
validateFn func(roots []common.Hash) validateFn func(roots []common.Hash)
}{ }{
// { // {
// name: "Valid block", // name: "Valid block",
// hash: validBlockHash, // hash: validBlockHash,
// config: nil, // Default TraceConfig // config: nil, // Default TraceConfig
// expectErr: false, // expectErr: false,
// validateFn: func(roots []common.Hash) { // validateFn: func(roots []common.Hash) {
// if len(roots) == 0 { // if len(roots) == 0 {
// t.Fatalf("expected non-empty intermediate roots, got none") // t.Fatalf("expected non-empty intermediate roots, got none")
// } // }
// if roots[len(roots)-1] != validBlock.Root() { // if roots[len(roots)-1] != validBlock.Root() {
// t.Fatalf("final intermediate root does not match block state root") // t.Fatalf("final intermediate root does not match block state root")
// } // }
// }, // },
// }, // },
{ {
name: "Bad block", name: "Bad block",
hash: badBlockHash, hash: badBlockHash,
config: nil, config: nil,
expectErr: false, expectErr: false,
validateFn: func(roots []common.Hash) { validateFn: func(roots []common.Hash) {
if len(roots) == 0 { if len(roots) == 0 {
t.Fatalf("expected non-empty intermediate roots, got none") t.Fatalf("expected non-empty intermediate roots, got none")
} }
}, },
}, },
{ {
name: "Genesis block", name: "Genesis block",
hash: genesisHash, hash: genesisHash,
config: nil, config: nil,
expectErr: true, expectErr: true,
expectMsg: "genesis is not traceable", expectMsg: "genesis is not traceable",
}, },
{ {
name: "Non-existent block", name: "Non-existent block",
hash: common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"), hash: common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"),
config: nil, config: nil,
expectErr: true, expectErr: true,
expectMsg: fmt.Sprintf("block %s not found", common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")), expectMsg: fmt.Sprintf("block %s not found", common.HexToHash("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")),
}, },
} }
// Execute test cases // Execute test cases
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
roots, err := api.IntermediateRoots(ctx, tc.hash, tc.config) roots, err := api.IntermediateRoots(ctx, tc.hash, tc.config)
if tc.expectErr { if tc.expectErr {
if err == nil || !strings.Contains(err.Error(), tc.expectMsg) { if err == nil || !strings.Contains(err.Error(), tc.expectMsg) {
t.Fatalf("expected error containing '%s', got: %v", tc.expectMsg, err) t.Fatalf("expected error containing '%s', got: %v", tc.expectMsg, err)
} }
return return
} }
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if tc.validateFn != nil { if tc.validateFn != nil {
tc.validateFn(roots) tc.validateFn(roots)
} }
}) })
} }
} }
func TestTracingWithOverrides(t *testing.T) { func TestTracingWithOverrides(t *testing.T) {