Skip to content
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 underpaying subsidy #121

Merged
merged 3 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ fn regression_empty_block_crash() -> Result {
Test::new()?
.command("find --blocksdir blocks 0 --slot --as-of-height 1")
.block()
.block_with_coinbase(false, true)
.block_with_coinbase(Coinbase {
include_coinbase_transaction: false,
..Default::default()
})
.expected_stdout("0.0.0.0\n")
.run()
}
Expand Down
26 changes: 21 additions & 5 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ struct Output {
tempdir: TempDir,
}

struct Coinbase {
include_coinbase_transaction: bool,
include_height: bool,
subsidy: u64,
}

impl Default for Coinbase {
fn default() -> Self {
Self {
include_coinbase_transaction: true,
include_height: true,
subsidy: 50 * COIN_VALUE,
}
}
}

struct Test {
args: Vec<String>,
blockfiles: Vec<usize>,
Expand Down Expand Up @@ -139,10 +155,10 @@ impl Test {
}

fn block(self) -> Self {
self.block_with_coinbase(true, true)
self.block_with_coinbase(Coinbase::default())
}

fn block_with_coinbase(mut self, coinbase: bool, include_height: bool) -> Self {
fn block_with_coinbase(mut self, coinbase: Coinbase) -> Self {
self.blocks.push(Block {
header: BlockHeader {
version: 0,
Expand All @@ -156,13 +172,13 @@ impl Test {
bits: 0,
nonce: 0,
},
txdata: if coinbase {
txdata: if coinbase.include_coinbase_transaction {
vec![Transaction {
version: 0,
lock_time: 0,
input: vec![TxIn {
previous_output: OutPoint::null(),
script_sig: if include_height {
script_sig: if coinbase.include_height {
script::Builder::new()
.push_scriptint(self.blocks.len().try_into().unwrap())
.into_script()
Expand All @@ -173,7 +189,7 @@ impl Test {
witness: vec![],
}],
output: vec![TxOut {
value: 50 * COIN_VALUE,
value: coinbase.subsidy,
script_pubkey: script::Builder::new().into_script(),
}],
}]
Expand Down
24 changes: 22 additions & 2 deletions tests/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,30 @@ fn duplicate_transaction_range() -> Result {
.command(
"list --blocksdir blocks d63a320a4b404d7933ca788e8f185f10e31e03bf6ab9fa4595bfedc2fcc5a4a8:0",
)
.block_with_coinbase(true, false)
.block_with_coinbase(true, false)
.block_with_coinbase(Coinbase {
include_height: false,
..Default::default()
})
.block_with_coinbase(Coinbase {
include_height: false,
..Default::default()
})
.block()
.transaction(&[(0, 0, 0)], 1)
.expected_stdout("[5000000000,10000000000)\n")
.run()
}

#[test]
fn underpay_subsidy() -> Result {
Test::new()?
.command(
"list --blocksdir blocks 12d57183977a1df616bafbb7dafbb4249e59d8f796ba556ad6bb75f0fa9fe0ea:0",
)
.block_with_coinbase(Coinbase {
subsidy: 50 * COIN_VALUE - 1,
..Default::default()
})
.expected_stdout("[0,4999999999)\n")
.run()
}