2024-04-15 06:23:23 +03:00
|
|
|
package systemcontracts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
2024-08-13 12:06:07 +03:00
|
|
|
"math/big"
|
2024-04-15 06:23:23 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2024-08-13 12:06:07 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2024-04-15 06:23:23 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAllCodesHash(t *testing.T) {
|
|
|
|
upgradesList := [13]map[string]*Upgrade{
|
|
|
|
ramanujanUpgrade,
|
|
|
|
nielsUpgrade,
|
|
|
|
mirrorUpgrade,
|
|
|
|
brunoUpgrade,
|
|
|
|
eulerUpgrade,
|
|
|
|
gibbsUpgrade,
|
|
|
|
moranUpgrade,
|
|
|
|
planckUpgrade,
|
|
|
|
lubanUpgrade,
|
|
|
|
platoUpgrade,
|
|
|
|
keplerUpgrade,
|
|
|
|
feynmanUpgrade,
|
|
|
|
feynmanFixUpgrade}
|
|
|
|
|
|
|
|
allCodes := make([]byte, 0, 10_000_000)
|
|
|
|
for _, hardfork := range upgradesList {
|
2024-05-14 11:37:17 +03:00
|
|
|
for _, network := range []string{mainNet, chapelNet} {
|
2024-04-15 06:23:23 +03:00
|
|
|
allCodes = append(allCodes, []byte(network)...)
|
|
|
|
if hardfork[network] != nil {
|
|
|
|
for _, addressConfig := range hardfork[network].Configs {
|
|
|
|
allCodes = append(allCodes, addressConfig.ContractAddr[:]...)
|
|
|
|
allCodes = append(allCodes, addressConfig.Code[:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
allCodeHash := sha256.Sum256(allCodes)
|
2024-05-14 11:37:17 +03:00
|
|
|
require.Equal(t, allCodeHash[:], common.Hex2Bytes("833cc0fc87c46ad8a223e44ccfdc16a51a7e7383525136441bd0c730f06023df"))
|
2024-04-15 06:23:23 +03:00
|
|
|
}
|
2024-08-13 12:06:07 +03:00
|
|
|
|
|
|
|
func TestUpgradeBuildInSystemContractNilInterface(t *testing.T) {
|
|
|
|
var (
|
|
|
|
config = params.BSCChainConfig
|
|
|
|
blockNumber = big.NewInt(37959559)
|
|
|
|
lastBlockTime uint64 = 1713419337
|
|
|
|
blockTime uint64 = 1713419340
|
|
|
|
statedb vm.StateDB
|
|
|
|
)
|
|
|
|
|
|
|
|
GenesisHash = params.BSCGenesisHash
|
|
|
|
|
|
|
|
UpgradeBuildInSystemContract(config, blockNumber, lastBlockTime, blockTime, statedb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpgradeBuildInSystemContractNilValue(t *testing.T) {
|
|
|
|
var (
|
|
|
|
config = params.BSCChainConfig
|
|
|
|
blockNumber = big.NewInt(37959559)
|
|
|
|
lastBlockTime uint64 = 1713419337
|
|
|
|
blockTime uint64 = 1713419340
|
|
|
|
statedb vm.StateDB = (*state.StateDB)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
GenesisHash = params.BSCGenesisHash
|
|
|
|
|
|
|
|
UpgradeBuildInSystemContract(config, blockNumber, lastBlockTime, blockTime, statedb)
|
|
|
|
}
|