mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
Move tests 4 (#2057)
* Convert tests to new staged sync 4 * More Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
parent
5f7418a393
commit
7ffd67e973
@ -25,6 +25,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon/turbo/stages"
|
||||
"github.com/ledgerwatch/erigon/turbo/trie"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -49,10 +50,8 @@ import (
|
||||
|
||||
// Create revival problem
|
||||
func TestCreate2Revive(t *testing.T) {
|
||||
t.Skip("switch to Erigon state readers/writers")
|
||||
|
||||
// Configure and generate a sample block chain
|
||||
db := ethdb.NewTestDB(t)
|
||||
var (
|
||||
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
address = crypto.PubkeyToAddress(key.PublicKey)
|
||||
@ -71,11 +70,12 @@ func TestCreate2Revive(t *testing.T) {
|
||||
address: {Balance: funds},
|
||||
},
|
||||
}
|
||||
genesis = gspec.MustCommit(db)
|
||||
signer = types.LatestSignerForChainID(nil)
|
||||
signer = types.LatestSignerForChainID(nil)
|
||||
)
|
||||
|
||||
engine := ethash.NewFaker()
|
||||
m := stages.MockWithGenesis(t, gspec, key)
|
||||
db := ethdb.NewObjectDatabase(m.DB)
|
||||
defer db.Close()
|
||||
|
||||
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
|
||||
defer contractBackend.Close()
|
||||
@ -95,7 +95,7 @@ func TestCreate2Revive(t *testing.T) {
|
||||
// In the third block, we cause the first child contract to selfdestruct
|
||||
// In the forth block, we create the second child contract, and we expect it to have a "clean slate" of storage,
|
||||
// i.e. without any storage items that "inherited" from the first child contract by mistake
|
||||
chain, err := core.GenerateChain(gspec.Config, genesis, engine, db.RwKV(), 4, func(i int, block *core.BlockGen) {
|
||||
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 4, func(i int, block *core.BlockGen) {
|
||||
var tx types.Transaction
|
||||
|
||||
switch i {
|
||||
@ -143,17 +143,17 @@ func TestCreate2Revive(t *testing.T) {
|
||||
}
|
||||
|
||||
// BLOCK 1
|
||||
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, chain.Blocks[0], true /* checkRoot */); err != nil {
|
||||
if err = m.InsertChain(chain.Slice(0, 1)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
st = state.New(state.NewDbStateReader(db))
|
||||
st = state.New(state.NewPlainStateReader(db))
|
||||
if !st.Exist(contractAddress) {
|
||||
t.Error("expected contractAddress to exist at the block 1", contractAddress.String())
|
||||
}
|
||||
|
||||
// BLOCK 2
|
||||
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, chain.Blocks[1], true /* checkRoot */); err != nil {
|
||||
if err = m.InsertChain(chain.Slice(1, 2)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var it *contracts.ReviveDeployEventIterator
|
||||
@ -167,7 +167,7 @@ func TestCreate2Revive(t *testing.T) {
|
||||
if it.Event.D != create2address {
|
||||
t.Errorf("Wrong create2address: %x, expected %x", it.Event.D, create2address)
|
||||
}
|
||||
st = state.New(state.NewDbStateReader(db))
|
||||
st = state.New(state.NewPlainStateReader(db))
|
||||
if !st.Exist(create2address) {
|
||||
t.Error("expected create2address to exist at the block 2", create2address.String())
|
||||
}
|
||||
@ -180,16 +180,16 @@ func TestCreate2Revive(t *testing.T) {
|
||||
}
|
||||
|
||||
// BLOCK 3
|
||||
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, chain.Blocks[2], true /* checkRoot */); err != nil {
|
||||
if err = m.InsertChain(chain.Slice(2, 3)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st = state.New(state.NewDbStateReader(db))
|
||||
st = state.New(state.NewPlainStateReader(db))
|
||||
if st.Exist(create2address) {
|
||||
t.Error("expected create2address to be self-destructed at the block 3", create2address.String())
|
||||
}
|
||||
|
||||
// BLOCK 4
|
||||
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, chain.Blocks[3], true /* checkRoot */); err != nil {
|
||||
if err = m.InsertChain(chain.Slice(3, 4)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
it, err = revive.FilterDeployEvent(nil)
|
||||
@ -202,7 +202,7 @@ func TestCreate2Revive(t *testing.T) {
|
||||
if it.Event.D != create2address {
|
||||
t.Errorf("Wrong create2address: %x, expected %x", it.Event.D, create2address)
|
||||
}
|
||||
st = state.New(state.NewDbStateReader(db))
|
||||
st = state.New(state.NewPlainStateReader(db))
|
||||
if !st.Exist(create2address) {
|
||||
t.Error("expected create2address to exist at the block 2", create2address.String())
|
||||
}
|
||||
|
@ -14,31 +14,27 @@
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package stages
|
||||
package stages_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
"github.com/ledgerwatch/erigon/turbo/stages"
|
||||
|
||||
"github.com/ledgerwatch/erigon/consensus/ethash"
|
||||
"github.com/ledgerwatch/erigon/core"
|
||||
"github.com/ledgerwatch/erigon/core/state"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/core/vm"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/eth/stagedsync"
|
||||
"github.com/ledgerwatch/erigon/ethdb"
|
||||
"github.com/ledgerwatch/erigon/log"
|
||||
"github.com/ledgerwatch/erigon/params"
|
||||
)
|
||||
|
||||
func ExampleGenerateChain() {
|
||||
db := ethdb.NewMemDatabase()
|
||||
defer db.Close()
|
||||
|
||||
func TestGenerateChain(t *testing.T) {
|
||||
var (
|
||||
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
||||
@ -56,16 +52,17 @@ func ExampleGenerateChain() {
|
||||
|
||||
// Ensure that key1 has some funds in the genesis block.
|
||||
gspec := &core.Genesis{
|
||||
Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int)},
|
||||
Config: ¶ms.ChainConfig{HomesteadBlock: new(big.Int), ChainID: big.NewInt(1)},
|
||||
Alloc: core.GenesisAlloc{addr1: {Balance: big.NewInt(1000000)}},
|
||||
}
|
||||
genesis := gspec.MustCommit(db)
|
||||
m := stages.MockWithGenesis(t, gspec, key1)
|
||||
db := ethdb.NewObjectDatabase(m.DB)
|
||||
|
||||
// This call generates a chain of 5 blocks. The function runs for
|
||||
// each block and adds different features to gen based on the
|
||||
// block index.
|
||||
signer := types.LatestSignerForChainID(nil)
|
||||
chain, err := core.GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db.RwKV(), 5, func(i int, gen *core.BlockGen) {
|
||||
chain, err := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, 5, func(i int, gen *core.BlockGen) {
|
||||
switch i {
|
||||
case 0:
|
||||
// In block 1, addr1 sends addr2 some ether.
|
||||
@ -97,19 +94,22 @@ func ExampleGenerateChain() {
|
||||
}
|
||||
|
||||
// Import the chain. This runs all block validation rules.
|
||||
if _, err := stagedsync.InsertBlocksInStages(db, ethdb.DefaultStorageMode, gspec.Config, &vm.Config{}, ethash.NewFaker(), chain.Blocks, true /* checkRoot */); err != nil {
|
||||
if err := m.InsertChain(chain); err != nil {
|
||||
fmt.Printf("insert error%v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
st := state.New(state.NewDbStateReader(db))
|
||||
fmt.Printf("last block: #%d\n", rawdb.ReadCurrentBlockDeprecated(db).Number())
|
||||
fmt.Println("balance of addr1:", st.GetBalance(addr1))
|
||||
fmt.Println("balance of addr2:", st.GetBalance(addr2))
|
||||
fmt.Println("balance of addr3:", st.GetBalance(addr3))
|
||||
// Output:
|
||||
// last block: #5
|
||||
// balance of addr1: 989000
|
||||
// balance of addr2: 10000
|
||||
// balance of addr3: 19687500000000001000
|
||||
if big.NewInt(5).Cmp(rawdb.ReadCurrentBlockDeprecated(db).Number()) != 0 {
|
||||
t.Errorf("wrong block number: %d", rawdb.ReadCurrentBlockDeprecated(db).Number())
|
||||
}
|
||||
if !uint256.NewInt().SetUint64(989000).Eq(st.GetBalance(addr1)) {
|
||||
t.Errorf("wrong balance of addr1: %s", st.GetBalance(addr1))
|
||||
}
|
||||
if !uint256.NewInt().SetUint64(10000).Eq(st.GetBalance(addr2)) {
|
||||
t.Errorf("wrong balance of addr2: %s", st.GetBalance(addr2))
|
||||
}
|
||||
if fmt.Sprintf("%s", st.GetBalance(addr3)) != "19687500000000001000" {
|
||||
t.Errorf("wrong balance of addr3: %s", st.GetBalance(addr3))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user