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"));
}
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());
}
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);
}
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 });
}
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 });
}
Aggregations