use of com.neemre.btcdcli4j.core.domain.RawBlock in project bisq-core by bisq-network.
the class BlockParserTest method testParseBlocks.
@Test
public void testParseBlocks() throws BitcoindException, CommunicationException, BlockNotConnectingException, RpcException {
// Setup blocks to test, starting before genesis
// Only the transactions related to bsq are relevant, no checks are done on correctness of blocks or other txs
// so hashes and most other data don't matter
long time = new Date().getTime();
int genesisHeight = 200;
int startHeight = 199;
int headHeight = 201;
Coin issuance = Coin.parseCoin("2.5");
RawTransaction genTx = new RawTransaction("gen block hash", 0, 0L, 0L, genesisTxId);
// Blockhashes
String bh199 = "blockhash199";
String bh200 = "blockhash200";
String bh201 = "blockhash201";
// Block 199
String cbId199 = "cbid199";
RawTransaction tx199 = new RawTransaction(bh199, 0, 0L, 0L, cbId199);
RawTx cbTx199 = new RawTx(cbId199, 199, bh199, time, ImmutableList.copyOf(new ArrayList<TxInput>()), ImmutableList.copyOf(asList(new RawTxOutput(0, 25, cbId199, null, null, null, 199))));
RawBlock block199 = new RawBlock(bh199, 10, 10, 199, 2, "root", asList(tx199), time, Long.parseLong("1234"), "bits", BigDecimal.valueOf(1), "chainwork", "previousBlockHash", bh200);
// Genesis Block
String cbId200 = "cbid200";
RawTransaction tx200 = new RawTransaction(bh200, 0, 0L, 0L, cbId200);
RawTx cbTx200 = new RawTx(cbId200, 200, bh200, time, ImmutableList.copyOf(new ArrayList<TxInput>()), ImmutableList.copyOf(asList(new RawTxOutput(0, 25, cbId200, null, null, null, 200))));
RawTx genesisTx = new RawTx(genesisTxId, 200, bh200, time, ImmutableList.copyOf(asList(new TxInput("someoldtx", 0, null))), ImmutableList.copyOf(asList(new RawTxOutput(0, issuance.getValue(), genesisTxId, null, null, null, 200))));
RawBlock block200 = new RawBlock(bh200, 10, 10, 200, 2, "root", asList(tx200, genTx), time, Long.parseLong("1234"), "bits", BigDecimal.valueOf(1), "chainwork", bh199, bh201);
// Block 201
// Make a bsq transaction
String cbId201 = "cbid201";
String bsqTx1Id = "bsqtx1";
RawTransaction tx201 = new RawTransaction(bh201, 0, 0L, 0L, cbId201);
RawTransaction txbsqtx1 = new RawTransaction(bh201, 0, 0L, 0L, bsqTx1Id);
long bsqTx1Value1 = Coin.parseCoin("2.4").getValue();
long bsqTx1Value2 = Coin.parseCoin("0.04").getValue();
RawTx cbTx201 = new RawTx(cbId201, 201, bh201, time, ImmutableList.copyOf(new ArrayList<TxInput>()), ImmutableList.copyOf(asList(new RawTxOutput(0, 25, cbId201, null, null, null, 201))));
RawTx bsqTx1 = new RawTx(bsqTx1Id, 201, bh201, time, ImmutableList.copyOf(asList(new TxInput(genesisTxId, 0, null))), ImmutableList.copyOf(asList(new RawTxOutput(0, bsqTx1Value1, bsqTx1Id, null, null, null, 201), new RawTxOutput(1, bsqTx1Value2, bsqTx1Id, null, null, null, 201))));
RawBlock block201 = new RawBlock(bh201, 10, 10, 201, 2, "root", asList(tx201, txbsqtx1), time, Long.parseLong("1234"), "bits", BigDecimal.valueOf(1), "chainwork", bh200, "nextBlockHash");
// TODO update test with new API
/*
new Expectations(rpcService) {{
rpcService.requestBlock(199);
result = block199;
rpcService.requestBlock(200);
result = block200;
rpcService.requestBlock(201);
result = block201;
rpcService.requestTx(cbId199, 199);
result = cbTx199;
rpcService.requestTx(cbId200, genesisHeight);
result = cbTx200;
rpcService.requestTx(genesisTxId, genesisHeight);
result = genesisTx;
rpcService.requestTx(cbId201, 201);
result = cbTx201;
rpcService.requestTx(bsqTx1Id, 201);
result = bsqTx1;
}};
// Running parseBlocks to build the bsq blockchain
fullNodeParser.parseBlocks(startHeight, headHeight, block -> {
});
*/
// Verify that the genesis tx has been added to the bsq blockchain with the correct issuance amount
/* assertTrue(bsqStateService.getGenesisTx().get() == genesisTx);
assertTrue(bsqStateService.getGenesisTotalSupply().getValue() == issuance.getValue());
// And that other txs are not added
assertFalse(bsqStateService.containsTx(cbId199));
assertFalse(bsqStateService.containsTx(cbId200));
assertFalse(bsqStateService.containsTx(cbId201));
// But bsq txs are added
assertTrue(bsqStateService.containsTx(bsqTx1Id));
TxOutput bsqOut1 = bsqStateService.getUnspentAndMatureTxOutput(bsqTx1Id, 0).get();
assertTrue(bsqStateService.isUnspent(bsqOut1));
assertTrue(bsqOut1.getValue() == bsqTx1Value1);
TxOutput bsqOut2 = bsqStateService.getUnspentAndMatureTxOutput(bsqTx1Id, 1).get();
assertTrue(bsqStateService.isUnspent(bsqOut2));
assertTrue(bsqOut2.getValue() == bsqTx1Value2);
assertFalse(bsqStateService.isTxOutputSpendable(genesisTxId, 0));
assertTrue(bsqStateService.isTxOutputSpendable(bsqTx1Id, 0));
assertTrue(bsqStateService.isTxOutputSpendable(bsqTx1Id, 1));*/
}
Aggregations