-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'phase/daedalus' of github.com:input-output-hk/mantis in…
…to feature/testECIP1017
- Loading branch information
Showing
23 changed files
with
200 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/test/scala/io/iohk/ethereum/ledger/ContractCreationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.iohk.ethereum.ledger | ||
|
||
import akka.util.ByteString | ||
import akka.util.ByteString.{empty => bEmpty} | ||
import io.iohk.ethereum.Mocks.MockVM | ||
import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup | ||
import io.iohk.ethereum.crypto.{generateKeyPair, kec256} | ||
import io.iohk.ethereum.domain.{Address, BlockchainImpl, TxLogEntry, UInt256} | ||
import io.iohk.ethereum.ledger.Ledger.PR | ||
import io.iohk.ethereum.nodebuilder.SecureRandomBuilder | ||
import io.iohk.ethereum.utils.{BlockchainConfig, Config, DaoForkConfig, MonetaryPolicyConfig} | ||
import io.iohk.ethereum.vm._ | ||
import org.scalatest.{FlatSpec, Matchers} | ||
import org.scalatest.prop.PropertyChecks | ||
import org.spongycastle.crypto.AsymmetricCipherKeyPair | ||
import org.spongycastle.crypto.params.ECPublicKeyParameters | ||
|
||
class ContractCreationSpec extends FlatSpec with PropertyChecks with Matchers { | ||
|
||
def createResult(world: InMemoryWorldStateProxy, | ||
gasUsed: BigInt, | ||
gasLimit: BigInt, | ||
gasRefund: BigInt, | ||
error: Option[ProgramError] = None, | ||
returnData: ByteString = bEmpty, | ||
logs: Seq[TxLogEntry] = Nil, | ||
addressesToDelete: Set[Address] = Set.empty): PR = | ||
ProgramResult( | ||
returnData = returnData, | ||
gasRemaining = gasLimit - gasUsed, | ||
world = world, | ||
addressesToDelete = addressesToDelete, | ||
logs = logs, | ||
gasRefund = gasRefund, | ||
internalTxs = Nil, | ||
error = error | ||
) | ||
|
||
it should "return an error if it's size is larger than the limit" in new TestSetup { | ||
val longContractCode = ByteString(Array.fill(codeSizeLimit + 1)(1.toByte)) | ||
val resultBeforeSaving = createResult(emptyWorld, gasUsed = defaultGasLimit / 2, | ||
gasLimit = defaultGasLimit, gasRefund = 0, error = None, returnData = longContractCode) | ||
|
||
val ledger = new LedgerImpl(new MockVM(), blockchain, blockchainConfig) | ||
val resultAfterSaving = ledger.saveNewContract(contractAddress, resultBeforeSaving, config) | ||
resultAfterSaving.error shouldBe Some(OutOfGas) | ||
} | ||
|
||
it should "not return an error if it's size is smaller than the limit" in new TestSetup { | ||
val shortContractCode = ByteString(Array.fill(codeSizeLimit - 1)(1.toByte)) | ||
val resultBeforeSaving = createResult(emptyWorld, gasUsed = defaultGasLimit / 2, | ||
gasLimit = defaultGasLimit, gasRefund = 0, error = None, returnData = shortContractCode) | ||
|
||
val ledger = new LedgerImpl(new MockVM(), blockchain, blockchainConfig) | ||
val resultAfterSaving = ledger.saveNewContract(contractAddress, resultBeforeSaving, config) | ||
resultAfterSaving.error shouldBe None | ||
} | ||
|
||
trait TestSetup extends EphemBlockchainTestSetup with SecureRandomBuilder { | ||
val keyPair: AsymmetricCipherKeyPair = generateKeyPair(secureRandom) | ||
val contractAddress = Address(kec256(keyPair.getPublic.asInstanceOf[ECPublicKeyParameters].getQ.getEncoded(false).tail)) | ||
|
||
val codeSizeLimit = 10 | ||
val defaultGasLimit = 5000 | ||
val config = EvmConfig.FrontierConfigBuilder(None) | ||
|
||
val emptyWorld = BlockchainImpl(storagesInstance.storages).getWorldStateProxy(-1, UInt256.Zero, None) | ||
|
||
val defaultBlockchainConfig = BlockchainConfig(Config.config) | ||
val blockchainConfig = new BlockchainConfig { | ||
override val maxCodeSize: Option[BigInt] = Some(codeSizeLimit) | ||
|
||
//unused | ||
override val daoForkConfig: Option[DaoForkConfig] = None | ||
override val customGenesisFileOpt: Option[String] = defaultBlockchainConfig.customGenesisFileOpt | ||
override val difficultyBombContinueBlockNumber: BigInt = defaultBlockchainConfig.difficultyBombContinueBlockNumber | ||
override val eip160BlockNumber: BigInt = defaultBlockchainConfig.eip160BlockNumber | ||
override val eip150BlockNumber: BigInt = defaultBlockchainConfig.eip150BlockNumber | ||
override val eip155BlockNumber: BigInt = defaultBlockchainConfig.eip155BlockNumber | ||
override val eip106BlockNumber: BigInt = defaultBlockchainConfig.eip106BlockNumber | ||
override val chainId: Byte = defaultBlockchainConfig.chainId | ||
override val frontierBlockNumber: BigInt = defaultBlockchainConfig.frontierBlockNumber | ||
override val monetaryPolicyConfig: MonetaryPolicyConfig = defaultBlockchainConfig.monetaryPolicyConfig | ||
override val difficultyBombPauseBlockNumber: BigInt = defaultBlockchainConfig.difficultyBombPauseBlockNumber | ||
override val homesteadBlockNumber: BigInt = defaultBlockchainConfig.homesteadBlockNumber | ||
override val accountStartNonce: UInt256 = defaultBlockchainConfig.accountStartNonce | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.