-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test for block with invalid extension application. #484
Open
oskin1
wants to merge
7
commits into
master
Choose a base branch
from
i483
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ad47ce1
Test for block with invalid extension application.
oskin1 668fc12
Duplicated checks removed.
oskin1 b6af8b3
Merge branch 'master' into i483
oskin1 2d51ab4
Tests for full block application moved to verifying tx cases.
oskin1 346e581
Merge remote-tracking branch 'origin/i483' into i483
oskin1 a288fbf
Merge branch 'master' into i483
oskin1 5e4e1ca
Merge branch 'master' into i483
oskin1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,10 +118,10 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
} | ||
getBestHeaderOpt shouldBe Some(block.header) | ||
|
||
val brokenBlock = generateInvalidFullBlock(block.header, wusAfterBlock) | ||
val brokenBlock = genInvalidFullBlock(block.header, wusAfterBlock) | ||
applyBlock(brokenBlock) shouldBe 'success | ||
|
||
val brokenBlock2 = generateInvalidFullBlock(block.header, wusAfterBlock) | ||
val brokenBlock2 = genInvalidFullBlock(block.header, wusAfterBlock) | ||
brokenBlock2.header should not be brokenBlock.header | ||
applyBlock(brokenBlock2) shouldBe 'success | ||
|
||
|
@@ -131,11 +131,11 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
} | ||
} | ||
|
||
private def generateInvalidFullBlock(parentHeader: Header, parentState: WrappedUtxoState) = { | ||
private def genInvalidFullBlock(parentHeader: Header, parentState: WrappedUtxoState) = { | ||
val extensionIn = extensionGen.sample.get | ||
val brokenBlockIn = validFullBlock(Some(parentHeader), parentState) | ||
val headTx = brokenBlockIn.blockTransactions.txs.head | ||
val wrongBoxId: ADKey = ADKey @@ Algos.hash("wrong input") | ||
val wrongBoxId: ADKey = ADKey !@@ Algos.hash("wrong input") | ||
val newInput = headTx.inputs.head.copy(boxId = wrongBoxId) | ||
val brokenTransactionsIn = brokenBlockIn.blockTransactions | ||
.copy(txs = headTx.copy(inputs = newInput +: headTx.inputs.tail) +: brokenBlockIn.blockTransactions.txs.tail) | ||
|
@@ -147,7 +147,48 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
ErgoFullBlock(brokenHeader, brokenTransactions, extension, Some(brokenProofs)) | ||
} | ||
|
||
private val t8 = TestCase("switching for a better chain") { fixture => | ||
private val t8 = TestCase("apply full block with invalid extension") { fixture => | ||
import fixture._ | ||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
val genesis = validFullBlock(parentOpt = None, us, bh) | ||
val wusAfterGenesis = WrappedUtxoState(us, bh, stateConstants).applyModifier(genesis).get | ||
if (verifyTransactions) { | ||
applyBlock(genesis) shouldBe 'success | ||
|
||
val block = validFullBlock(Some(genesis.header), wusAfterGenesis) | ||
val wusAfterBlock = wusAfterGenesis.applyModifier(block).get | ||
|
||
applyBlock(block) shouldBe 'success | ||
getBestHeaderOpt shouldBe Some(block.header) | ||
if (verifyTransactions) { | ||
getRootHash shouldBe Algos.encode(wusAfterBlock.rootHash) | ||
} | ||
getBestHeaderOpt shouldBe Some(block.header) | ||
|
||
val brokenBlock = genBlockWithInvalidExtension(block.header, wusAfterBlock) | ||
applyBlock(brokenBlock) shouldBe 'success | ||
|
||
val brokenBlock2 = genBlockWithInvalidExtension(block.header, wusAfterBlock) | ||
brokenBlock2.header should not be brokenBlock.header | ||
applyBlock(brokenBlock2) shouldBe 'success | ||
|
||
getBestFullBlockOpt shouldBe Some(block) | ||
getRootHash shouldBe Algos.encode(wusAfterBlock.rootHash) | ||
getBestHeaderOpt shouldBe Some(block.header) | ||
} | ||
} | ||
|
||
private def genBlockWithInvalidExtension(parentHeader: Header, parentState: WrappedUtxoState) = { | ||
val extensionIn = extensionGen.sample.get | ||
val validBlockIn = validFullBlock(Some(parentHeader), parentState) | ||
val brokenExtension = extensionIn.copy( | ||
mandatoryFields = extensionIn.mandatoryFields :+ extensionIn.mandatoryFields.head, | ||
headerId = validBlockIn.id | ||
) | ||
validBlockIn.copy(extension = brokenExtension) | ||
} | ||
|
||
private val t9 = TestCase("switching for a better chain") { fixture => | ||
import fixture._ | ||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
val genesis = validFullBlock(parentOpt = None, us, bh) | ||
|
@@ -180,7 +221,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
getRootHash shouldBe Algos.encode(chain2block2.header.stateRoot) | ||
} | ||
|
||
private val t9 = TestCase("UTXO state should generate adProofs and put them in history") { fixture => | ||
private val t10 = TestCase("UTXO state should generate adProofs and put them in history") { fixture => | ||
import fixture._ | ||
if (stateType == StateType.Utxo) { | ||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
|
@@ -195,7 +236,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
} | ||
} | ||
|
||
private val t10 = TestCase("NodeViewHolder start from inconsistent state") { fixture => | ||
private val t11 = TestCase("NodeViewHolder start from inconsistent state") { fixture => | ||
import fixture._ | ||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
val genesis = validFullBlock(parentOpt = None, us, bh) | ||
|
@@ -215,7 +256,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
getRootHash shouldBe Algos.encode(block1.header.stateRoot) | ||
} | ||
|
||
private val t11 = TestCase("apply payload in incorrect order") { fixture => | ||
private val t12 = TestCase("apply payload in incorrect order") { fixture => | ||
import fixture._ | ||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
val genesis = validFullBlock(parentOpt = None, us, bh) | ||
|
@@ -240,7 +281,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
getBestFullBlockEncodedId shouldBe Some(chain2block2.header.encodedId) | ||
} | ||
|
||
private val t12 = TestCase("Do not apply txs with wrong header id") { fixture => | ||
private val t13 = TestCase("Do not apply txs with wrong header id") { fixture => | ||
import fixture._ | ||
|
||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
|
@@ -291,7 +332,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
expectMsgType[SyntacticallySuccessfulModifier[BlockTransactions]] | ||
} | ||
|
||
private val t13 = TestCase("Do not apply wrong adProofs") { fixture => | ||
private val t14 = TestCase("Do not apply wrong adProofs") { fixture => | ||
import fixture._ | ||
|
||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
|
@@ -321,7 +362,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
expectMsgType[SyntacticallySuccessfulModifier[ADProofs]] | ||
} | ||
|
||
private val t14 = TestCase("do not apply genesis block header if " + | ||
private val t15 = TestCase("do not apply genesis block header if " + | ||
"it's not equal to genesisId from config") { fixture => | ||
import fixture._ | ||
updateConfig(genesisIdConfig(modifierIdGen.sample)) | ||
|
@@ -341,7 +382,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
getHistoryHeight shouldBe -1 | ||
} | ||
|
||
private val t15 = TestCase("apply genesis block header if it's equal to genesisId from config") { fixture => | ||
private val t16 = TestCase("apply genesis block header if it's equal to genesisId from config") { fixture => | ||
import fixture._ | ||
val (us, bh) = createUtxoState(Some(nodeViewHolderRef)) | ||
val block = validFullBlock(None, us, bh) | ||
|
@@ -359,7 +400,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
getHeightOf(block.header.id) shouldBe Some(0) | ||
} | ||
|
||
val cases: List[TestCase] = List(t1, t2, t3, t4, t5, t6, t7, t8, t9) | ||
val cases: List[TestCase] = List(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) | ||
NodeViewTestConfig.allConfigs.foreach { c => | ||
cases.foreach { t => | ||
property(s"${t.name} - $c") { | ||
|
@@ -368,7 +409,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
} | ||
} | ||
|
||
val verifyingTxCases = List(t10, t11, t12, t13) | ||
val verifyingTxCases = List(t11, t12, t13, t14) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should also move t7 and t8 here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
NodeViewTestConfig.verifyTxConfigs.foreach { c => | ||
verifyingTxCases.foreach { t => | ||
|
@@ -378,7 +419,7 @@ class ErgoNodeViewHolderSpec extends ErgoPropertyTest with NodeViewTestOps with | |
} | ||
} | ||
|
||
val genesisIdTestCases = List(t14, t15) | ||
val genesisIdTestCases = List(t15, t16) | ||
def genesisIdConfig(expectedGenesisIdOpt: Option[ModifierId])(protoSettings: ErgoSettings): ErgoSettings = { | ||
protoSettings.copy(chainSettings = protoSettings.chainSettings.copy(genesisId = expectedGenesisIdOpt)) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double
verifyTransactions
check