Search in sources :

Example 6 with ScriptBuilder2

use of it.unica.tcs.lib.script.ScriptBuilder2 in project balzac by balzac-lang.

the class AbstractScriptBuilderTest method test_optimize3_sb.

@Test
public void test_optimize3_sb() {
    Script s = new ScriptBuilder2().op(OP_TOALTSTACK).op(OP_FROMALTSTACK).number(4).op(OP_TOALTSTACK).op(OP_FROMALTSTACK).optimize().build();
    assertEquals(1, s.getChunks().size());
    assertArrayEquals(s.getProgram(), new byte[] { OP_4 });
}
Also used : Script(org.bitcoinj.script.Script) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) Test(org.junit.Test)

Example 7 with ScriptBuilder2

use of it.unica.tcs.lib.script.ScriptBuilder2 in project balzac by balzac-lang.

the class AbstractScriptBuilderTest method test_optimize_sb.

@Test
public void test_optimize_sb() {
    Script s = new ScriptBuilder2().op(OP_TOALTSTACK).op(OP_FROMALTSTACK).optimize().build();
    assertEquals(0, s.getChunks().size());
    assertArrayEquals(s.getProgram(), new byte[] {});
}
Also used : Script(org.bitcoinj.script.Script) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) Test(org.junit.Test)

Example 8 with ScriptBuilder2

use of it.unica.tcs.lib.script.ScriptBuilder2 in project balzac by balzac-lang.

the class AbstractScriptBuilderTest method test_optimize4_sb.

@Test
public void test_optimize4_sb() {
    Script s = new ScriptBuilder2().op(OP_TOALTSTACK).op(OP_TOALTSTACK).op(OP_FROMALTSTACK).op(OP_FROMALTSTACK).number(4).optimize().build();
    assertEquals(1, s.getChunks().size());
    assertArrayEquals(s.getProgram(), new byte[] { OP_4 });
}
Also used : Script(org.bitcoinj.script.Script) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) Test(org.junit.Test)

Example 9 with ScriptBuilder2

use of it.unica.tcs.lib.script.ScriptBuilder2 in project balzac by balzac-lang.

the class ScriptBuilder2Test method test_size.

@Test
public void test_size() {
    ScriptBuilder2 sb = new ScriptBuilder2();
    assertEquals(0, sb.size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
    sb.number(5);
    assertEquals(1, sb.size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
}
Also used : ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) Test(org.junit.Test)

Example 10 with ScriptBuilder2

use of it.unica.tcs.lib.script.ScriptBuilder2 in project balzac by balzac-lang.

the class ScriptBuilder2Test method test_signature.

@Test
public void test_signature() throws KeyStoreException {
    ScriptBuilder2 sb = new ScriptBuilder2();
    assertEquals(0, sb.size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
    ECKey k1 = new ECKey();
    ECKey k2 = new ECKey();
    ecks.addKey(k1);
    ecks.addKey(k2);
    sb.signaturePlaceholder(k1, SigHash.ALL, false);
    sb.signaturePlaceholder(k2, SigHash.ALL, false);
    System.out.println(sb);
    assertEquals(2, sb.size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(2, sb.signatureSize());
    Transaction tx = new Transaction(new MainNetParams());
    tx.addInput(new TransactionInput(new MainNetParams(), null, new byte[] { 42, 42 }));
    sb.setAllSignatures(ecks, tx, 0, new byte[] {});
    System.out.println(sb);
    assertEquals(2, sb.size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
}
Also used : Transaction(org.bitcoinj.core.Transaction) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) ECKey(org.bitcoinj.core.ECKey) MainNetParams(org.bitcoinj.params.MainNetParams) TransactionInput(org.bitcoinj.core.TransactionInput) Test(org.junit.Test)

Aggregations

ScriptBuilder2 (it.unica.tcs.lib.script.ScriptBuilder2)17 Test (org.junit.Test)17 ECKey (org.bitcoinj.core.ECKey)8 SigHash (org.bitcoinj.core.Transaction.SigHash)6 Script (org.bitcoinj.script.Script)6 Transaction (org.bitcoinj.core.Transaction)1 TransactionInput (org.bitcoinj.core.TransactionInput)1 MainNetParams (org.bitcoinj.params.MainNetParams)1