|
| 1 | +// Copyright 2024 the libevm authors. |
| 2 | +// |
| 3 | +// The libevm additions to go-ethereum are free software: you can redistribute |
| 4 | +// them and/or modify them under the terms of the GNU Lesser General Public License |
| 5 | +// as published by the Free Software Foundation, either version 3 of the License, |
| 6 | +// or (at your option) any later version. |
| 7 | +// |
| 8 | +// The libevm additions are distributed in the hope that they will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
| 11 | +// General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU Lesser General Public License |
| 14 | +// along with the go-ethereum library. If not, see |
| 15 | +// <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package triedb |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + |
| 24 | + "github.com/ava-labs/libevm/common" |
| 25 | + "github.com/ava-labs/libevm/ethdb" |
| 26 | + "github.com/ava-labs/libevm/triedb/database" |
| 27 | +) |
| 28 | + |
| 29 | +func TestDBOverride(t *testing.T) { |
| 30 | + config := &Config{ |
| 31 | + DBOverride: func(d ethdb.Database, c *Config) BackendOverride { |
| 32 | + return override{} |
| 33 | + }, |
| 34 | + } |
| 35 | + |
| 36 | + db := NewDatabase(nil, config) |
| 37 | + got, err := db.Reader(common.Hash{}) |
| 38 | + require.NoError(t, err) |
| 39 | + if _, ok := got.(reader); !ok { |
| 40 | + t.Errorf("with non-nil %T.DBOverride, %T.Reader() got concrete type %T; want %T", config, db, got, reader{}) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +type override struct { |
| 45 | + PathBackend |
| 46 | +} |
| 47 | + |
| 48 | +type reader struct { |
| 49 | + database.Reader |
| 50 | +} |
| 51 | + |
| 52 | +func (override) Reader(common.Hash) (database.Reader, error) { |
| 53 | + return reader{}, nil |
| 54 | +} |
0 commit comments