Skip to content

Commit

Permalink
Update the unit test to test the case
Browse files Browse the repository at this point in the history
  • Loading branch information
djordon committed Oct 1, 2024
1 parent 294a0dd commit 2c78511
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion signer/src/storage/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ mod tests {
blocks.push(NakamotoBlock::consensus_deserialize(bytes).unwrap());
}

let deployer = StacksAddress::new(2, Hash160([0u8; 20]));
let deployer = StacksAddress::burn_address(false);
let txs = extract_relevant_transactions(&blocks, &deployer);
assert!(txs.is_empty());

Expand All @@ -1755,5 +1755,32 @@ mod tests {

let txs = extract_relevant_transactions(&blocks, &deployer);
assert_eq!(txs.len(), 1);

// We've just seen that if the deployer supplied here matches the
// address in the transaction, then we will consider it a relevant
// transaction. Now what if someone tries to pull a fast one by
// deploying their own modified version of the sBTC smart contracts
// and creating contract calls against that? We'll the address of
// these contract calls won't match the ones that we are interested
// in and we will filter them out. We test that now,
let contract_call = TransactionContractCall {
// This is the address of the poser that deployed their own
// versions of the sBTC smart contracts.
address: StacksAddress::new(2, Hash160([1; 20])),
contract_name: ContractName::from(contract_name),
function_name: ClarityName::from(function_name),
function_args: Vec::new(),
};
// The last transaction in the last nakamoto block is a legit
// transaction. Let's remove it and replace it with a non-legit
// one.
let last_block = blocks.last_mut().unwrap();
let mut tx = last_block.txs.pop().unwrap();
tx.payload = TransactionPayload::ContractCall(contract_call);
last_block.txs.push(tx);

// Now there aren't any relevant transactions in the block
let txs = extract_relevant_transactions(&blocks, &deployer);
assert!(txs.is_empty());
}
}

0 comments on commit 2c78511

Please sign in to comment.