Skip to content

Commit

Permalink
Merge branch 'master' into TestStatefulPrecompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush authored Oct 24, 2022
2 parents a610d7b + 47c03fd commit 992d683
Show file tree
Hide file tree
Showing 97 changed files with 2,272 additions and 1,185 deletions.
1 change: 0 additions & 1 deletion accounts/abi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error) {
// coded as just like uint256,bool,uint256
virtualArgs += getTypeSize(arg.Type)/32 - 1
}

retval = append(retval, marshalledValue)
}
return retval, nil
Expand Down
34 changes: 15 additions & 19 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ type SimulatedBackend struct {
acceptedBlock *types.Block // Currently accepted block that will be imported on request
acceptedState *state.StateDB // Currently accepted state that will be the active on request

events *filters.EventSystem // Event system for filtering log events live
events *filters.EventSystem // for filtering log events live
filterSystem *filters.FilterSystem // for filtering database logs

config *params.ChainConfig
}
Expand All @@ -118,7 +119,11 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
blockchain: blockchain,
config: genesis.Config,
}
backend.events = filters.NewEventSystem(&filterBackend{database, blockchain, backend}, false)

filterBackend := &filterBackend{database, blockchain, backend}
backend.filterSystem = filters.NewFilterSystem(filterBackend, filters.Config{})
backend.events = filters.NewEventSystem(backend.filterSystem, false)

backend.rollback(blockchain.CurrentBlock())
return backend
}
Expand Down Expand Up @@ -594,6 +599,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call
for lo+1 < hi {
mid := (hi + lo) / 2
failed, _, err := executable(mid)

// If the error is not nil(consensus error), it means the provided message
// call or transaction will never be accepted no matter how much gas it is
// assigned. Return the error directly, don't struggle any more
Expand Down Expand Up @@ -646,7 +652,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.Cal
// User specified the legacy gas field, convert to 1559 gas typing
call.GasFeeCap, call.GasTipCap = call.GasPrice, call.GasPrice
} else {
// User specified 1559 gas feilds (or none), use those
// User specified 1559 gas fields (or none), use those
if call.GasFeeCap == nil {
call.GasFeeCap = new(big.Int)
}
Expand Down Expand Up @@ -728,7 +734,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query interfaces.Filt
var filter *filters.Filter
if query.BlockHash != nil {
// Block filter requested, construct a single-shot filter
filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain, b}, *query.BlockHash, query.Addresses, query.Topics)
filter = b.filterSystem.NewBlockFilter(*query.BlockHash, query.Addresses, query.Topics)
} else {
// Initialize unset filter boundaries to run from genesis to chain head
from := int64(0)
Expand All @@ -740,7 +746,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query interfaces.Filt
to = query.ToBlock.Int64()
}
// Construct the range filter
filter, _ = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain, b}, from, to, query.Addresses, query.Topics)
filter, _ = b.filterSystem.NewRangeFilter(from, to, query.Addresses, query.Topics)
}
// Run the filter and return all the logs
logs, err := filter.Logs(ctx)
Expand Down Expand Up @@ -890,7 +896,8 @@ func (fb *filterBackend) GetMaxBlocksPerRequest() int64 {
return eth.DefaultSettings.MaxBlocksPerRequest
}

func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }
func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }

func (fb *filterBackend) EventMux() *event.TypeMux { panic("not supported") }

func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumber) (*types.Header, error) {
Expand All @@ -912,19 +919,8 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
}

func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
number := rawdb.ReadHeaderNumber(fb.db, hash)
if number == nil {
return nil, nil
}
receipts := rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config())
if receipts == nil {
return nil, nil
}
logs := make([][]*types.Log, len(receipts))
for i, receipt := range receipts {
logs[i] = receipt.Logs
}
func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) {
logs := rawdb.ReadLogs(fb.db, hash, number)
return logs, nil
}

Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value {
func set(dst, src reflect.Value) error {
dstType, srcType := dst.Type(), src.Type()
switch {
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid():
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid() && (dst.Elem().Type().Kind() == reflect.Ptr || dst.Elem().CanSet()):
return set(dst.Elem(), src)
case dstType.Kind() == reflect.Ptr && dstType.Elem() != reflect.TypeOf(big.Int{}):
return set(dst.Elem(), src)
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type reflectTest struct {

var reflectTests = []reflectTest{
{
name: "OneToOneCorrespondance",
name: "OneToOneCorrespondence",
args: []string{"fieldA"},
struc: struct {
FieldA int `abi:"fieldA"`
Expand Down
1 change: 0 additions & 1 deletion accounts/abi/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func lengthPrefixPointsTo(index int, output []byte) (start int, length int, err
lengthBig := new(big.Int).SetBytes(output[offsetEnd-32 : offsetEnd])

totalSize := new(big.Int).Add(bigOffsetEnd, lengthBig)

if totalSize.BitLen() > 63 {
return 0, 0, fmt.Errorf("abi: length larger than int64: %v", totalSize)
}
Expand Down
19 changes: 12 additions & 7 deletions accounts/abi/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
func TestUnpack(t *testing.T) {
for i, test := range packUnpackTests {
t.Run(strconv.Itoa(i)+" "+test.def, func(t *testing.T) {
// Unpack
//Unpack
def := fmt.Sprintf(`[{ "name" : "method", "type": "function", "outputs": %s}]`, test.def)
abi, err := JSON(strings.NewReader(def))
if err != nil {
Expand Down Expand Up @@ -235,7 +235,7 @@ var unpackTests = []unpackTest{
func TestLocalUnpackTests(t *testing.T) {
for i, test := range unpackTests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
// Unpack
//Unpack
def := fmt.Sprintf(`[{ "name" : "method", "type": "function", "outputs": %s}]`, test.def)
abi, err := JSON(strings.NewReader(def))
if err != nil {
Expand Down Expand Up @@ -316,7 +316,7 @@ type methodMultiOutput struct {
func methodMultiReturn(require *require.Assertions) (ABI, []byte, methodMultiOutput) {
const definition = `[
{ "name" : "multi", "type": "function", "outputs": [ { "name": "Int", "type": "uint256" }, { "name": "String", "type": "string" } ] }]`
expected := methodMultiOutput{big.NewInt(1), "hello"}
var expected = methodMultiOutput{big.NewInt(1), "hello"}

abi, err := JSON(strings.NewReader(definition))
require.NoError(err)
Expand All @@ -342,7 +342,7 @@ func TestMethodMultiReturn(t *testing.T) {

abi, data, expected := methodMultiReturn(require.New(t))
bigint := new(big.Int)
testCases := []struct {
var testCases = []struct {
dest interface{}
expected interface{}
error string
Expand All @@ -362,6 +362,11 @@ func TestMethodMultiReturn(t *testing.T) {
&[]interface{}{&expected.Int, &expected.String},
"",
"Can unpack into a slice",
}, {
&[]interface{}{&bigint, ""},
&[]interface{}{&expected.Int, expected.String},
"",
"Can unpack into a slice without indirection",
}, {
&[2]interface{}{&bigint, new(string)},
&[2]interface{}{&expected.Int, &expected.String},
Expand Down Expand Up @@ -502,7 +507,7 @@ func TestMultiReturnWithDeeplyNestedArray(t *testing.T) {
// construct the test array, each 3 char element is joined with 61 '0' chars,
// to from the ((3 + 61) * 0.5) = 32 byte elements in the array.
buff.Write(common.Hex2Bytes(strings.Join([]string{
"", // empty, to apply the 61-char separator to the first element as well.
"", //empty, to apply the 61-char separator to the first element as well.
"111", "112", "113", "121", "122", "123",
"211", "212", "213", "221", "222", "223",
"311", "312", "313", "321", "322", "323",
Expand Down Expand Up @@ -796,7 +801,7 @@ func TestUnpackTuple(t *testing.T) {
type r struct {
Result v
}
ret0 := new(r)
var ret0 = new(r)
err = abi.UnpackIntoInterface(ret0, "tuple", buff.Bytes())

if err != nil {
Expand Down Expand Up @@ -855,7 +860,7 @@ func TestUnpackTuple(t *testing.T) {
A *big.Int
}
var ret Ret
expected := Ret{
var expected = Ret{
FieldS: S{
A: big.NewInt(1),
B: []*big.Int{big.NewInt(1), big.NewInt(2)},
Expand Down
10 changes: 5 additions & 5 deletions accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestWatchNoDir(t *testing.T) {
time.Sleep(100 * time.Millisecond)

// Create the directory and copy a key file into it.
os.MkdirAll(dir, 0o700)
os.MkdirAll(dir, 0700)
defer os.RemoveAll(dir)
file := filepath.Join(dir, "aaa")
if err := cp.CopyFile(file, cachetestAccounts[0].URL.Path); err != nil {
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
t.Skip("FLAKY")
t.Parallel()

// Create a temporary kesytore to test with
// Create a temporary keystore to test with
rand.Seed(time.Now().UnixNano())
dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-watch-test-%d-%d", os.Getpid(), rand.Int()))
ks := NewKeyStore(dir, LightScryptN, LightScryptP)
Expand All @@ -341,7 +341,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
time.Sleep(100 * time.Millisecond)

// Create the directory and copy a key file into it.
os.MkdirAll(dir, 0o700)
os.MkdirAll(dir, 0700)
defer os.RemoveAll(dir)
file := filepath.Join(dir, "aaa")

Expand Down Expand Up @@ -394,7 +394,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
time.Sleep(1000 * time.Millisecond)

// Now replace file contents with crap
if err := os.WriteFile(file, []byte("foo"), 0o600); err != nil {
if err := os.WriteFile(file, []byte("foo"), 0600); err != nil {
t.Fatal(err)
return
}
Expand All @@ -411,5 +411,5 @@ func forceCopyFile(dst, src string) error {
if err != nil {
return err
}
return os.WriteFile(dst, data, 0o644)
return os.WriteFile(dst, data, 0644)
}
4 changes: 2 additions & 2 deletions accounts/keystore/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type fileCache struct {
func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, error) {
t0 := time.Now()

// List all the failes from the keystore folder
// List all the files from the keystore folder
files, err := os.ReadDir(keyDir)
if err != nil {
return nil, nil, nil, err
Expand All @@ -71,7 +71,7 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
log.Trace("Ignoring file on account scan", "path", path)
continue
}
// Gather the set of all and fresly modified files
// Gather the set of all and freshly modified files
all.Add(path)

info, err := fi.Info()
Expand Down
6 changes: 3 additions & 3 deletions accounts/keystore/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestKeyStore(t *testing.T) {
if err != nil {
t.Fatalf("account file %s doesn't exist (%v)", a.URL, err)
}
if runtime.GOOS != "windows" && stat.Mode() != 0o600 {
t.Fatalf("account file has wrong mode: got %o, want %o", stat.Mode(), 0o600)
if runtime.GOOS != "windows" && stat.Mode() != 0600 {
t.Fatalf("account file has wrong mode: got %o, want %o", stat.Mode(), 0600)
}
if !ks.HasAddress(a.Address) {
t.Errorf("HasAccount(%x) should've returned true", a.Address)
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestSignRace(t *testing.T) {
// Tests that the wallet notifier loop starts and stops correctly based on the
// addition and removal of wallet event subscriptions.
func TestWalletNotifierLifecycle(t *testing.T) {
// Create a temporary kesytore to test with
// Create a temporary keystore to test with
_, ks := tmpKeyStore(t, false)

// Ensure that the notification updater is not running yet
Expand Down
Loading

0 comments on commit 992d683

Please sign in to comment.