Exemple #1
0
    def test_Appcall1(self):

        with self.assertRaises(Exception):
            Compiler.instance().load('%s/boa_test/example/blockchain/AppCallTest2.py' % TestContract.dirname).default

        with self.assertRaises(Exception):
            Compiler.instance().load('%s/boa_test/example/blockchain/AppCallTest3.py' % TestContract.dirname).default
    def test_NFT_1(self):

        output = Compiler.instance().load('nft_template.py').default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, ['name', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), TOKEN_NAME)

        tx, results, total_ops, engine = TestBuild(out, ['symbol', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), TOKEN_SYMBOL)

        tx, results, total_ops, engine = TestBuild(out, ['decimals', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), TOKEN_DECIMALS)

        tx, results, total_ops, engine = TestBuild(out, ['nonexistentmethod', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 0)

	# mint a token
        owner = bytearray(TOKEN_CONTRACT_OWNER)
        tx, results, total_ops, engine = TestBuild(out, ['mintToken', parse_param([owner,1,'token1ROData','https://example.com/images/1.png','token1ROData'])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        # now circulation should be equal to 1
        tx, results, total_ops, engine = TestBuild(out, ['totalSupply', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)

        # now the owner should have a balance of 1
        tx, results, total_ops, engine = TestBuild(out, ['balanceOf', parse_param([bytearray(TOKEN_CONTRACT_OWNER)])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)
    def test_NFT_3_mint(self):

        output = Compiler.instance().load('nft_template.py').default
        out = output.write()

        TestContract.dispatched_events = []

	# mint another token
        owner = bytearray(TOKEN_CONTRACT_OWNER)
        tx, results, total_ops, engine = TestBuild(out, ['mintToken', parse_param([owner,2,'token2ROData','https://example.com/images/2.png','token2ROData'])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        # it should dispatch an event
        self.assertEqual(len(TestContract.dispatched_events), 8)
        evt = TestContract.dispatched_events[0]
        self.assertIsInstance(evt, NotifyEvent)
        self.assertEqual(evt.addr_to, self.wallet_1_script_hash)

        # now the total circulation should be bigger
        tx, results, total_ops, engine = TestBuild(out, ['totalSupply', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 2)

	# trying to mint a token with an existing token ID should fail
        owner = bytearray(TOKEN_CONTRACT_OWNER)
        tx, results, total_ops, engine = TestBuild(out, ['mintToken', parse_param([owner,2,'token2ROData','https://example.com/images/2.png','token2ROData'])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 0)
    def test_ManyElif(self):

        output = Compiler.instance().load(
            '%s/boa_test/example/TestManyElif.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [1], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 2)

        tx, results, total_ops, engine = TestBuild(out, [3], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 4)

        tx, results, total_ops, engine = TestBuild(out, [16],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 17)

        tx, results, total_ops, engine = TestBuild(out, [22],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), -1)
Exemple #5
0
    def test_iterators(self):

        output = Compiler.instance().load('%s/boa_test/example/demo/IteratorTest.py' % TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [1], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        tx, results, total_ops, engine = TestBuild(out, [2], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [3], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        res = [i.GetString() for i in results[0].GetArray()]
        self.assertEqual(res, ['a', 'c', 'f'])

        tx, results, total_ops, engine = TestBuild(out, [4], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        res = [i.GetBigInteger() for i in results[0].GetArray()]
        self.assertEqual(res, [1, 4, 13])

        tx, results, total_ops, engine = TestBuild(out, [5], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [6], self.GetWallet1(), '02', '01')
        self.assertEqual(len(results), 1)
        res = [i.GetBigInteger() for i in results[0].GetArray()]
        self.assertEqual(res, [1, 4, 13])
Exemple #6
0
    def test_Account(self):

        output = Compiler.instance().load('%s/boa_test/example/blockchain/AccountTest.py' % TestContract.dirname).default
        out = output.write()
        string_ouput = output.to_s()
        self.assertGreater(len(string_ouput), 0)

        account = self.wallet_1_script_hash.Data

        bad_account = bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacE)')

        tx, results, total_ops, engine = TestBuild(out, ['get_hash', bad_account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        tx, results, total_ops, engine = TestBuild(out, ['get_hash', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), account)

        tx, results, total_ops, engine = TestBuild(out, ['get_votes', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetArray(), [])

        tx, results, total_ops, engine = TestBuild(out, ['get_balance_gas', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1399980000)

        tx, results, total_ops, engine = TestBuild(out, ['get_balance_neo', account], self.GetWallet1(), '07', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 5000000000)
Exemple #7
0
    def test_ICOTemplate_7_burn(self):
        output = Compiler.instance().load('%s/ico_template.py' % TestContract.dirname).default
        out = output.write()

        # burn tokens
        burn_amt = 1000000000 * 100000000
        tx, results, total_ops, engine = TestBuild(out, ['burn', '[%s]' % burn_amt ], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        # tokens burned
        tx, results, total_ops, engine = TestBuild(out, ['tokens_burned', '[]'], self.GetWallet2(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), burn_amt)

        # tokens available for sale
        tx, results, total_ops, engine = TestBuild(out, ['crowdsale_available', '[]'], self.GetWallet2(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 4000000000 * 100000000 - 54000000000000 - burn_amt)

        # burned is not counted in totalSupply
        tx, results, total_ops, engine = TestBuild(out, ['circulation', '[]'], self.GetWallet1(), '0705', '05')
        in_circ = results[0].GetBigInteger()
        tx, results, total_ops, engine = TestBuild(out, ['totalSupply', '[]'], self.GetWallet1(), '0705', '05')
        total_supply = results[0].GetBigInteger()
        self.assertEqual(in_circ, total_supply + burn_amt)
Exemple #8
0
    def test_AddTest(self):

        output = Compiler.instance().load(
            '%s/boa_test/example/AddTest.py' %
            TestContract.dirname).default.write()

        tx, results, total_ops, engine = TestBuild(output, [2],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 4)

        tx, results, total_ops, engine = TestBuild(output, [23234],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(results[0].GetBigInteger(), 23236)

        tx, results, total_ops, engine = TestBuild(output, [0],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(results[0].GetBigInteger(), 2)

        tx, results, total_ops, engine = TestBuild(output, [-112],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(results[0].GetBigInteger(), -110)
Exemple #9
0
    def setUpClass(cls):
        super(TestNotifyDebugEvents, cls).setUpClass()
        output = Compiler.instance().load('%s/sc_debug_events.py' %
                                          os.path.dirname(__file__)).default
        cls.script = output.write()

        settings.set_log_smart_contract_events(False)
Exemple #10
0
    def test_CompareTest1(self):

        output = Compiler.instance().load('%s/boa_test/example/CompareTest1.py' % TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [1, 2, 3, 4], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 11)

        tx, results, total_ops, engine = TestBuild(out, [1, 2, 4, 3], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)

        tx, results, total_ops, engine = TestBuild(out, [1, 4, 3, 5], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 22)

        tx, results, total_ops, engine = TestBuild(out, [4, 1, 5, 3], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [9, 1, 3, 5], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 10)

        tx, results, total_ops, engine = TestBuild(out, [9, 5, 3, 5], self.GetWallet1(), '02020202', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)
Exemple #11
0
    def test_Take(self):
        output = Compiler.instance().load('%s/boa_test/example/TakeTest.py' %
                                          TestContract.dirname).default
        out = output.write()
        tx, results, total_ops, engine = TestBuild(out, [2], self.GetWallet1(),
                                                   '02', '07')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), 'he')

        tx, results, total_ops, engine = TestBuild(out, [0], self.GetWallet1(),
                                                   '02', '07')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), '')

        tx, results, total_ops, engine = TestBuild(out, [12],
                                                   self.GetWallet1(), '02',
                                                   '07')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), 'helloworld12')

        tx, results, total_ops, engine = TestBuild(out, [40],
                                                   self.GetWallet1(), '02',
                                                   '07')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), 'helloworld1234567')

        tx, results, total_ops, engine = TestBuild(out, [-2],
                                                   self.GetWallet1(), '02',
                                                   '07')
        self.assertEqual(len(results), 0)
Exemple #12
0
    def test_list0(self):
        output = Compiler.instance().load('%s/boa_test/example/ArrayTest.py' %
                                          TestContract.dirname).default
        out = output.write()
        tx, results, total_ops, engine = TestBuild(out, [0], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)

        tx, results, total_ops, engine = TestBuild(out, [1], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 6)

        tx, results, total_ops, engine = TestBuild(out, [2], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [4], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)

        tx, results, total_ops, engine = TestBuild(out, [8], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 9)
Exemple #13
0
def BuildAndRun(arguments,
                wallet,
                verbose=True,
                min_fee=DEFAULT_MIN_FEE,
                invocation_test_mode=True):

    arguments, from_addr = get_from_addr(arguments)
    arguments, invoke_attrs = get_tx_attr_from_args(arguments)
    arguments, owners = get_owners_from_params(arguments)
    path = get_arg(arguments)
    contract_script = Compiler.instance().load_and_save(path)

    newpath = path.replace('.py', '.avm')
    logger.info("Saved output to %s " % newpath)

    debug_map_path = path.replace('.py', '.debug.json')
    debug_map = None
    if os.path.exists(debug_map_path):
        with open(debug_map_path, 'r') as dbg:
            debug_map = json.load(dbg)

    return DoRun(contract_script,
                 arguments,
                 wallet,
                 path,
                 verbose,
                 from_addr,
                 min_fee,
                 invocation_test_mode,
                 debug_map=debug_map,
                 invoke_attrs=invoke_attrs,
                 owners=owners)
Exemple #14
0
    def test_Storage2(self):
        output = Compiler.instance().load('%s/boa_test/example/blockchain/StorageTest.py' % TestContract.dirname).default
        out = output.write()

        snapshot = GetBlockchain()._db.createSnapshot()

        tx, results, total_ops, engine = TestBuild(out, ['sget', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')

        tx, results, total_ops, engine = TestBuild(out, ['sput', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(out, ['sget', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 10000000000)

        tx, results, total_ops, engine = TestBuild(out, ['sdel', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(out, ['sget', 100, 10000000000], self.GetWallet1(), '070505', '05', snapshot=snapshot)
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')
Exemple #15
0
    def test_M1(self):
        output = Compiler.instance().load('%s/boa_test/example/ModuleVariableTest1.py' % TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(), '', '07')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)
Exemple #16
0
    def test_2_SmartNEP5(self):

        timestamp = round(time.time())
        test_neo_acc = 'NEO'+ str(timestamp)[-8:]
        test_neo_acc2 = 'NEO'+ str(timestamp-10000)[-8:]

        print('=========== NA =============')
        output = Compiler.instance().load('./nasc.py').default
        out = output.write()

        print('===== init =====')
        tx, results, total_ops, engine = TestBuild(out, ['init', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertIn(results[0].GetString() ,['NASC initialized.', 'Uknown operation'])
        
        print('===== test =====')
        tx, results, total_ops, engine = TestBuild(out, ['na_test', '[]'], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString() ,'NASC is up!')

        tx, results, total_ops, engine = TestBuild(out, ['na_register', parse_param([test_neo_acc, self.wallet_1_script_hash.Data, 4, self.wallet_1_script_hash.Data, 1519912704])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString() , 'Alias registered: '+ test_neo_acc)

        tx, results, total_ops, engine = TestBuild(out, ['smart_balanceOf', parse_param([test_neo_acc])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger() , 10000)

        tx, results, total_ops, engine = TestBuild(out, ['na_register', parse_param([test_neo_acc2, self.wallet_3_script_hash.Data, 4, self.wallet_3_script_hash.Data, 1519912704])], self.GetWallet3(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString() , 'Alias registered: '+ test_neo_acc2)

        print('===== transfer =====')
        tx, results, total_ops, engine = TestBuild(out, ['smart_transfer', parse_param([test_neo_acc, test_neo_acc2, 500])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), 'Transfer completed.')

        tx, results, total_ops, engine = TestBuild(out, ['smart_balanceOf', parse_param([test_neo_acc2])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger() , 500)

        print('===== aprove =====')
        tx, results, total_ops, engine = TestBuild(out, ['smart_approve', parse_param([test_neo_acc, test_neo_acc2, 50])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'Spender can withdraw (from your address): 2')

        print('===== allowance =====')
        tx, results, total_ops, engine = TestBuild(out, ['smart_allowance', parse_param([test_neo_acc, test_neo_acc2])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'Spender can withdraw: 2')

        print('===== transfeFrom =====')
        tx, results, total_ops, engine = TestBuild(out, ['smart_transferFrom', parse_param([test_neo_acc2, test_neo_acc, test_neo_acc2, 50])], self.GetWallet3(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetString(), 'TransferFrom completed.')

        print('===== balanceOf =====')
        tx, results, total_ops, engine = TestBuild(out, ['smart_balanceOf', parse_param([test_neo_acc2])], self.GetWallet1(), '0710', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger() , 550)
    def test_MethodTest6(self):
        output = Compiler.instance().load('%s/boa_test/example/Fibonacci.py' %
                                          TestContract.dirname,
                                          use_nep8=False).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [4], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 3)

        tx, results, total_ops, engine = TestBuild(out, [5], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 5)

        tx, results, total_ops, engine = TestBuild(out, [6], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)

        tx, results, total_ops, engine = TestBuild(out, [7], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 13)

        tx, results, total_ops, engine = TestBuild(out, [11],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 89)
Exemple #18
0
    def test_Triggers(self):

        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/TriggerTypeTest.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, [1], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), bytearray(b'\x10'))

        tx, results, total_ops, engine = TestBuild(out, [2], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), bytearray(b'\x00'))

        tx, results, total_ops, engine = TestBuild(out, [3], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), bytearray(b'\x20'))

        tx, results, total_ops, engine = TestBuild(out, [0], self.GetWallet1(),
                                                   '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), -1)
Exemple #19
0
    def test_Storage(self):
        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/StorageTest.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(
            out, ['sget', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')

        tx, results, total_ops, engine = TestBuild(
            out, ['sput', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(
            out, ['sget', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'blah')

        tx, results, total_ops, engine = TestBuild(
            out, ['sdel', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'\x01')

        tx, results, total_ops, engine = TestBuild(
            out, ['sget', 'something', 'blah'], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), b'')
Exemple #20
0
    def test_is_invalid_operation(self):
        output = Compiler.instance().load('%s/nos_bookmark.py' % BASE_DIR)
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, ['into_the_void', '[]'], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), False)
Exemple #21
0
    def test_ICOTemplate_4_attachments(self):

        output = Compiler.instance().load('%s/ico_template.py' % TestContract.dirname).default
        out = output.write()

        # test mint tokens without being kyc verified
        tx, results, total_ops, engine = TestBuild(out, ['get_attachments', '[]', '--attach-neo=10'], self.GetWallet3(), '0705', '05')
        self.assertEqual(len(results), 1)
        attachments = results[0].GetArray()
        self.assertEqual(len(attachments), 4)

        fn = FunctionCode(out, '0705', '05')

        self.assertEqual(attachments[0].GetByteArray(), fn.ScriptHash().Data)
        self.assertEqual(attachments[1].GetByteArray(), self.wallet_3_script_hash.Data)
        self.assertEqual(attachments[2].GetBigInteger(), Fixed8.FromDecimal(10).value)
        self.assertEqual(attachments[3].GetBigInteger(), 0)

        tx, results, total_ops, engine = TestBuild(out, ['get_attachments', '[]'], self.GetWallet3(), '0705', '05')
        self.assertEqual(len(results), 1)
        attachments = results[0].GetArray()
        self.assertEqual(len(attachments), 4)

        self.assertEqual(attachments[1].GetByteArray(), bytearray())
        self.assertEqual(attachments[2].GetBigInteger(), 0)
        self.assertEqual(attachments[3].GetBigInteger(), 0)

        tx, results, total_ops, engine = TestBuild(out, ['get_attachments', '[]', '--attach-neo=3', '--attach-gas=3.12'], self.GetWallet1(), '0705', '05')
        self.assertEqual(len(results), 1)
        attachments = results[0].GetArray()
        self.assertEqual(len(attachments), 4)
        self.assertEqual(attachments[1].GetByteArray(), self.wallet_1_script_hash.Data)
        self.assertEqual(attachments[2].GetBigInteger(), Fixed8.FromDecimal(3).value)
        self.assertEqual(attachments[3].GetBigInteger(), Fixed8.FromDecimal(3.12).value)
Exemple #22
0
    def test_Contract(self):
        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/ContractTest.py' %
            TestContract.dirname).default
        out = output.write()

        contract_hash = bytearray(
            b"\xccN\xe2\xf1\xc9\xf4\xe0x\'V\xda\xbf$m\nO\xe6\n\x03T")
        contract_script = '746b4c04000000004c04000000004c04000000006161681e416e745368617265732e426c6f636b636861696e2e47657448656967687461681d416e745368617265732e426c6f636b636861696e2e476574426c6f636b744c0400000000948c6c766b947275744c0400000000936c766b9479744c0400000000948c6c766b947961681d416e745368617265732e4865616465722e47657454696d657374616d70a0744c0401000000948c6c766b947275744c0401000000948c6c766b9479641b004c0400000000744c0402000000948c6c766b947275623200744c0401000000936c766b9479744c0402000000936c766b9479617cac744c0402000000948c6c766b947275620300744c0402000000948c6c766b947961748c6c766b946d748c6c766b946d748c6c766b946d746c768c6b946d746c768c6b946d746c768c6b946d6c7566'

        tx, results, total_ops, engine = TestBuild(
            out, ['get_contract', contract_hash], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertIsInstance(results[0].GetInterface(), ContractState)

        tx, results, total_ops, engine = TestBuild(
            out, ['get_script', contract_hash], self.GetWallet1(), '070505',
            '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray().hex(), contract_script)

        tx, results, total_ops, engine = TestBuild(
            out, ['get_storage_context', contract_hash], self.GetWallet1(),
            '070505', '05')
        self.assertEqual(len(results), 0)

        tx, results, total_ops, engine = TestBuild(out,
                                                   ['destroy', contract_hash],
                                                   self.GetWallet1(), '070505',
                                                   '05')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 1)
Exemple #23
0
    def test_Appcall2(self):

        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/AppCallTest.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, ['add', 3, 5],
                                                   self.GetWallet1(), '070202',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 8)

        tx, results, total_ops, engine = TestBuild(out, ['sub', 3, 5],
                                                   self.GetWallet1(), '070202',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), -2)

        tx, results, total_ops, engine = TestBuild(out, ['mul', 3, 5],
                                                   self.GetWallet1(), '070202',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 15)

        tx, results, total_ops, engine = TestBuild(out, ['notfound', 3, 5],
                                                   self.GetWallet1(), '070202',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 0)
Exemple #24
0
 def test_list2(self):
     output = Compiler.instance().load('%s/boa_test/example/ArrayTest2.py' %
                                       TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetByteArray(), bytearray(b'\xa0'))
Exemple #25
0
    def test_Runtime(self):

        dispatched_events = []
        dispatched_logs = []

        def on_notif(evt):
            dispatched_events.append(evt)

        def on_log(evt):
            dispatched_logs.append(evt)

        events.on(SmartContractEvent.RUNTIME_NOTIFY, on_notif)
        events.on(SmartContractEvent.RUNTIME_LOG, on_log)

        output = Compiler.instance().load(
            '%s/boa_test/example/blockchain/RuntimeTest.py' %
            TestContract.dirname).default
        out = output.write()

        tx, results, total_ops, engine = TestBuild(out, ['get_time', 1],
                                                   self.GetWallet1(), '0202',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetByteArray(), bytearray(b'\x01r\x04Z'))

        tx, results, total_ops, engine = TestBuild(out, [
            'check_witness',
            bytearray(b'S\xefB\xc8\xdf!^\xbeZ|z\xe8\x01\xcb\xc3\xac/\xacI)')
        ], self.GetWallet1(), '02', '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)

        tx, results, total_ops, engine = TestBuild(out, ['log', 'hello'],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)
        self.assertEqual(len(dispatched_logs), 1)
        self.assertEqual(dispatched_logs[0].event_payload.Value, 'hello')

        tx, results, total_ops, engine = TestBuild(out, ['notify', 1234],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBoolean(), True)
        self.assertEqual(len(dispatched_events), 1)
        self.assertEqual(
            int.from_bytes(dispatched_events[0].event_payload.Value, 'little'),
            1234)

        tx, results, total_ops, engine = TestBuild(out, ['get_trigger', 1234],
                                                   self.GetWallet1(), '02',
                                                   '02')
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].GetBigInteger(), 16)

        events.off(SmartContractEvent.RUNTIME_NOTIFY, on_notif)
        events.off(SmartContractEvent.RUNTIME_LOG, on_log)
Exemple #26
0
def BuildAndRun(arguments, wallet, verbose=True, min_fee=DEFAULT_MIN_FEE):
    path = get_arg(arguments)

    contract_script = Compiler.instance().load_and_save(path)

    newpath = path.replace('.py', '.avm')
    print("Saved output to %s " % newpath)

    return DoRun(contract_script, arguments, wallet, path, verbose, min_fee=min_fee)
 def test_MethodTest4(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/MethodTest4.py' % TestContract.dirname,
         use_nep8=False).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetBigInteger(), 63)
 def test_dict_has_key(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/DictTestHasKey.py' %
         TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetBigInteger(), 22)
Exemple #29
0
 def test_list6(self):
     output = Compiler.instance().load(
         '%s/boa_test/example/ArrayReverseTest.py' %
         TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '02')
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0].GetString(), 'blah')
Exemple #30
0
 def test_Range1(self):
     output = Compiler.instance().load('%s/boa_test/example/RangeTest.py' %
                                       TestContract.dirname).default
     out = output.write()
     tx, results, total_ops, engine = TestBuild(out, [], self.GetWallet1(),
                                                '', '07')
     self.assertEqual(len(results), 1)
     res = results[0].GetArray()
     self.assertEqual(len(res), 20)
Exemple #31
0
def BuildAndRun(arguments, wallet, verbose=True, min_fee=DEFAULT_MIN_FEE, invocation_test_mode=True):
    arguments, from_addr = get_from_addr(arguments)
    path = get_arg(arguments)

    contract_script = Compiler.instance().load_and_save(path)

    newpath = path.replace('.py', '.avm')
    logger.info("Saved output to %s " % newpath)

    debug_map_path = path.replace('.py', '.debug.json')
    debug_map = None
    if os.path.exists(debug_map_path):
        with open(debug_map_path, 'r') as dbg:
            debug_map = json.load(dbg)

    return DoRun(contract_script, arguments, wallet, path, verbose, from_addr, min_fee, invocation_test_mode, debug_map=debug_map)
    def setUpClass(cls):
        super(TestNotifyDebugEvents, cls).setUpClass()
        output = Compiler.instance().load('%s/sc_debug_events.py' % os.path.dirname(__file__)).default
        cls.script = output.write()

        settings.set_log_smart_contract_events(False)
 def setUpClass(cls):
     super(TestVMErrors, cls).setUpClass()
     output = Compiler.instance().load('%s/sc_vm_errors.py' % os.path.dirname(__file__)).default
     cls.script = output.write()
     settings.set_loglevel(DEBUG)