Search in sources :

Example 1 with TxIdIndexTuple

use of bisq.core.dao.blockchain.vo.util.TxIdIndexTuple in project bisq-core by bisq-network.

the class FullNodeParserTest method testIsBsqTx.

@Test
public void testIsBsqTx() {
    // Setup a basic transaction with two inputs
    int height = 200;
    String hash = "abc123";
    long time = new Date().getTime();
    Tx tx = new Tx("vo", height, hash, time, asList(new TxInput("tx1", 0), new TxInput("tx1", 1)), asList(new TxOutput(0, 101, "tx1", null, null, null, height)));
    // Return one spendable txoutputs with value, for three test cases
    // 1) - null, 0     -> not BSQ transaction
    // 2) - 100, null   -> BSQ transaction
    // 3) - 0, 100      -> BSQ transaction
    new Expectations(readModel) {

        {
            // Expectations can be recorded on mocked instances, either with specific matching arguments or catch all
            // http://jmockit.github.io/tutorial/Mocking.html#results
            // Results are returned in the order they're recorded, so in this case for the first call to
            // getSpendableTxOutput("tx1", 0) the return value will be Optional.empty()
            // for the second call the return is Optional.of(new TxOutput(0,... and so on
            readModel.getUnspentAndMatureTxOutput(new TxIdIndexTuple("tx1", 0));
            result = Optional.empty();
            result = Optional.of(new TxOutput(0, 100, "txout1", null, null, null, height));
            result = Optional.of(new TxOutput(0, 0, "txout1", null, null, null, height));
            readModel.getUnspentAndMatureTxOutput(new TxIdIndexTuple("tx1", 1));
            result = Optional.of(new TxOutput(0, 0, "txout2", null, null, null, height));
            result = Optional.empty();
            result = Optional.of(new TxOutput(0, 100, "txout2", null, null, null, height));
        }
    };
    // First time there is no BSQ value to spend so it's not a bsq transaction
    assertFalse(bsqTxController.isBsqTx(height, tx));
    // Second time there is BSQ in the first txout
    assertTrue(bsqTxController.isBsqTx(height, tx));
    // Third time there is BSQ in the second txout
    assertTrue(bsqTxController.isBsqTx(height, tx));
}
Also used : Expectations(mockit.Expectations) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) Tx(bisq.core.dao.blockchain.vo.Tx) TxIdIndexTuple(bisq.core.dao.blockchain.vo.util.TxIdIndexTuple) Date(java.util.Date) TxInput(bisq.core.dao.blockchain.vo.TxInput) Test(org.junit.Test)

Aggregations

Tx (bisq.core.dao.blockchain.vo.Tx)1 TxInput (bisq.core.dao.blockchain.vo.TxInput)1 TxOutput (bisq.core.dao.blockchain.vo.TxOutput)1 TxIdIndexTuple (bisq.core.dao.blockchain.vo.util.TxIdIndexTuple)1 Date (java.util.Date)1 Expectations (mockit.Expectations)1 Test (org.junit.Test)1