예제 #1
0
 def test_valid_hash256(self):
     for script in [
         [types.Five(), types.Hash256(), types.Push(b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'), types.EqualVerify()],
         [types.Five(), types.Sha256(), types.Push(b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'), types.EqualVerify()],
     ]:
         script = LInstructions(script)
         self._do_context(script)
예제 #2
0
 def test_invalid_hash256(self):
     for script in [
         [types.Five(), types.Hash256(), types.Push(b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'), types.EqualVerify()],
         [types.Five(), types.Sha256(), types.Push(b'\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01'), types.EqualVerify()],
     ]:
         script = LInstructions(script)
         self.assertRaises(IRError, self._do_context, script)
예제 #3
0
 def test_null_ops(self):
     for script in [
         [types.Five(), types.Zero(), types.Add()],
         [types.Zero(), types.Five(), types.Add()],
         [types.Five(), types.Zero(), types.Sub()],
     ]:
         self._do_test('OP_5', script)
예제 #4
0
    def test_arithmetic_ops(self):
        script = [types.Five(), types.Five(), types.Equal(), types.Not()]
        self._do_test('OP_5 OP_5 OP_NUMNOTEQUAL', script)

        script = [types.Five(), types.Push(b'\x01\x02\x03\x04'), types.Equal(), types.Not()]
        self._do_test('OP_5 01020304 OP_NUMNOTEQUAL', script)

        # A value longer than 4 bytes won't be optimized this way.
        script = [types.Five(), types.Push(b'\x01\x02\x03\x04\x05'), types.Equal(), types.Not()]
        self._do_test('OP_5 0102030405 OP_EQUAL OP_NOT', script)
예제 #5
0
    def test_assume_to_pick_or_roll(self):
        script = [types.Five(), types.Assumption('testItem'), types.Add()]
        self._do_test('OP_5 OP_ADD', script)

        self._reset_table(['testItem'])
        script = [types.Five(), types.Five(), types.Assumption('testItem'), types.Add()]
        self._do_test('OP_5 OP_5 OP_2 OP_ROLL OP_ADD', script)

        self._reset_table(['testItem'])
        script = [types.Five(), types.Five(), types.Assumption('testItem'), types.Add(), types.Assumption('testItem')]
        self._do_test('OP_5 OP_5 OP_2 OP_PICK OP_ADD OP_2 OP_ROLL', script)
예제 #6
0
    def test_optimize_stack_ops(self):
        script = [types.Five(), types.One(), types.Pick()]
        self._do_test('OP_5 OP_OVER', script)

        script = [types.Five(), types.One(), types.Roll(), types.Drop()]
        self._do_test('OP_5 OP_NIP', script)

        script = [types.Zero(), types.Pick()]
        self._do_test('OP_DUP', script)

        script = [types.Five(), types.Zero(), types.Roll()]
        self._do_test('OP_5', script)

        script = [types.Five(), types.Six(), types.One(), types.Roll(), types.One(), types.Roll()]
        self._do_test('OP_5 OP_6', script)
예제 #7
0
 def test_small_int(self):
     script = LInstructions([types.Five(), types.Six(), types.Seven(), types.Two(), types.Pick()])
     self._do_context(script)
     pick = script[4]
     self.assertIsInstance(pick, types.Pick)
     self.assertEqual([1, 4], pick.args)
     node = script[pick.idx - pick.args[1]]
     self.assertEqual(5, node.value)
예제 #8
0
    def test_shortcut_ops(self):
        for script in [
            [types.Five(), types.One(), types.Add()],
            [types.One(), types.Five(), types.Add()],
        ]:
            self._do_test('OP_5 OP_1ADD', script)

        self._do_test('OP_1ADD', [types.Assumption('testItem'), types.One(), types.Add()])

        script = [types.Five(), types.One(), types.Sub()]
        self._do_test('OP_5 OP_1SUB', script)

        for script in [
            [types.Five(), types.Two(), types.Mul()],
            [types.Two(), types.Five(), types.Mul()],
        ]:
            self._do_test('OP_5 OP_2MUL', script)

        self._do_test('OP_2MUL', [types.Assumption('testItem'), types.Two(), types.Mul()])

        script = [types.Five(), types.Two(), types.Div()]
        self._do_test('OP_5 OP_2DIV', script)

        script = [types.Five(), types.One(), types.Negate()]
        self._do_test('OP_5 OP_1NEGATE', script)
예제 #9
0
    def test_optimize_hashes(self):
        script = [types.Five(), types.Sha256(), types.Sha256()]
        self._do_test('OP_5 OP_HASH256', script)

        script = [types.Five(), types.Sha256(), types.RipeMD160()]
        self._do_test('OP_5 OP_HASH160', script)
예제 #10
0
 def test_optimize_dup_and_checksig(self):
     script = [types.Five(), types.Dup(), types.Six(), types.CheckSig()]
     self._do_test('OP_5 OP_6 OP_CHECKSIG', script)
예제 #11
0
    def test_merge_op_and_verify(self):
        script = [types.Five(), types.Five(), types.Equal(), types.Verify()]
        self._do_test('OP_5 OP_5 OP_EQUALVERIFY', script)

        script = [types.Five(), types.Five(), types.NumEqual(), types.Verify()]
        self._do_test('OP_5 OP_5 OP_NUMEQUALVERIFY', script)
예제 #12
0
 def test_repeated_ops(self):
     script = [types.Five(), types.Five(), types.Five(), types.Drop(), types.Drop()]
     self._do_test('OP_5 OP_5 OP_5 OP_2DROP', script)
예제 #13
0
 def test_implicit_assume(self):
     script = [types.Assumption('testItem'), types.Five(), types.Add()]
     self._do_test('OP_5 OP_ADD', script)
예제 #14
0
 def test_promote_return(self):
     for script in [
         [types.Five(), types.Return()],
         [types.Return(), types.Five(), types.Return()],
     ]:
         self._do_test('OP_RETURN OP_5', script)
예제 #15
0
 def test_multiple_optimization_occurrences(self):
     script = [types.Five(), types.Five(), types.Equal(), types.Verify(), types.Five(), types.Five(), types.Equal(), types.Verify()]
     self._do_test('OP_5 OP_5 OP_EQUALVERIFY OP_5 OP_5 OP_EQUALVERIFY', script)