Search in sources :

Example 1 with ScriptBuilder2

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

the class ScriptBuilder2Test method test_derialize_freeVariable.

@Test
public void test_derialize_freeVariable() {
    String serialScript = "15 [var,Donald,java.lang.String]";
    ScriptBuilder2 res = new ScriptBuilder2(serialScript);
    assertEquals(1, res.getFreeVariables().size());
    assertEquals(2, res.size());
    assertEquals(String.class, res.getType("Donald"));
}
Also used : ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) Test(org.junit.Test)

Example 2 with ScriptBuilder2

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

the class ScriptBuilder2Test method test_freeVariable.

@Test
public void test_freeVariable() {
    ScriptBuilder2 sb = new ScriptBuilder2();
    assertEquals(0, sb.size());
    assertEquals(0, sb.getVariables().size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
    sb.addVariable("foo", Long.class);
    assertTrue(sb.hasVariable("foo"));
    assertEquals(1, sb.size());
    assertEquals(1, sb.getVariables().size());
    assertEquals(1, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
    sb = sb.bindVariable("foo", 5L);
    assertEquals(1, sb.size());
    assertEquals(1, sb.getVariables().size());
    assertEquals(1, sb.getBoundVariables().size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
    Script s = sb.build();
    assertEquals("5", s.toString());
    // sb state is unchanged
    assertEquals(1, sb.size());
    assertEquals(1, sb.getVariables().size());
    assertEquals(1, sb.getBoundVariables().size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
    sb = sb.removeVariable("foo");
    assertEquals(0, sb.size());
    assertFalse(sb.hasVariable("foo"));
    assertEquals(0, sb.getVariables().size());
    assertEquals(0, sb.getFreeVariables().size());
    assertEquals(0, sb.signatureSize());
}
Also used : Script(org.bitcoinj.script.Script) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) Test(org.junit.Test)

Example 3 with ScriptBuilder2

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

the class ScriptBuilder2Test method test_serialize_signature1.

@Test
public void test_serialize_signature1() {
    ECKey key = new ECKey();
    SigHash hashType = SigHash.ALL;
    ScriptBuilder2 sb = new ScriptBuilder2();
    sb.number(15);
    sb.signaturePlaceholder(key, hashType, false);
    String expected = "15 [sig," + ECKeyStore.getUniqueID(key) + ",**]";
    String actual = sb.serialize();
    assertEquals(expected, actual);
}
Also used : SigHash(org.bitcoinj.core.Transaction.SigHash) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) ECKey(org.bitcoinj.core.ECKey) Test(org.junit.Test)

Example 4 with ScriptBuilder2

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

the class AbstractScriptBuilderTest method test_optimize2_sb.

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

Example 5 with ScriptBuilder2

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

the class AbstractScriptBuilderTest method test_optimize5_sb.

@Test
public void test_optimize5_sb() {
    Script s = new ScriptBuilder2().op(OP_TOALTSTACK).op(OP_TOALTSTACK).number(4).op(OP_FROMALTSTACK).op(OP_FROMALTSTACK).optimize().build();
    assertEquals(5, s.getChunks().size());
    assertArrayEquals(s.getProgram(), new byte[] { OP_TOALTSTACK, OP_TOALTSTACK, OP_4, OP_FROMALTSTACK, OP_FROMALTSTACK });
}
Also used : Script(org.bitcoinj.script.Script) ScriptBuilder2(it.unica.tcs.lib.script.ScriptBuilder2) 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