Exemplo n.º 1
0
    def test_strip_loan(self):
        chain = BlockchainSpider.chain(self.tree, 1)
        self.assertEqual(chain[-1]['action'], 'LOAN')

        chain = BlockchainSpider.strip_loan(chain)
        self.assertEqual(len(chain), 4)
        self.assertEqual(chain[-1]['action'], 'UNCONSIGN')
Exemplo n.º 2
0
    def test_strip_loan(self):
        chain = BlockchainSpider.chain(self.tree, 1)
        self.assertEqual(chain[-1]['action'], 'LOAN')

        chain = BlockchainSpider.strip_loan(chain)
        self.assertEqual(len(chain), 4)
        self.assertEqual(chain[-1]['action'], 'UNCONSIGN')
Exemplo n.º 3
0
    def test_chain(self):
        tree = self.tree

        chain0 = BlockchainSpider.chain(tree, 0)
        self.assertEqual(len(chain0), 2)

        chain1 = BlockchainSpider.chain(tree, 1)
        self.assertEqual(len(chain1), 5)
Exemplo n.º 4
0
    def test_chain(self):
        tree = self.tree

        chain0 = BlockchainSpider.chain(tree, 0)
        self.assertEqual(len(chain0), 2)

        chain1 = BlockchainSpider.chain(tree, 1)
        self.assertEqual(len(chain1), 5)
Exemplo n.º 5
0
def spider(rpcuser, rpcpassword, host, port):
    from spool import BlockchainSpider
    return BlockchainSpider(
        service='daemon',
        username=rpcuser,
        password=rpcpassword,
        host=host,
        port=port,
        testnet=True,
    )
Exemplo n.º 6
0
def test_blockchainspider_init(rpcuser, rpcpassword, host, port):
    from spool.spoolex import BlockchainSpider
    blockchain_spider = BlockchainSpider(
        testnet=True,
        service='daemon',
        username=rpcuser,
        password=rpcpassword,
        host=host,
        port=port,
    )
    assert isinstance(blockchain_spider._t, Transactions)
    assert blockchain_spider._t.testnet is True
    assert blockchain_spider._t._service._username == rpcuser
    assert blockchain_spider._t._service._password == rpcpassword
    assert blockchain_spider._t._service._host == host
    assert blockchain_spider._t._service._port == port
    assert isinstance(blockchain_spider._t._service, BitcoinDaemonService)
Exemplo n.º 7
0
 def test_data(self):
     tree = self.tree
     data = {0: BlockchainSpider.chain(tree, 0)}
     self.assertDictEqual(data, {0: [{'action': 'EDITIONS',
                                      'edition_number': 0,
                                      'from_address': u'mqXz83H4LCxjf2ie8hYNsTRByvtfV43Pa7',
                                      'number_editions': 10,
                                      'piece_address': u'myr2VcDnPKf997sjXx6rUFc4CtFH9sxNVS',
                                      'timestamp_utc': 1432649855,
                                      'to_address': u'n2sQHoUghWUgSM8msqdmCim8pZ635YjoCD',
                                      'txid': u'fb22bbb83161f6904f1803ee1cdbed1b5836eb9ac51b102564400989780b48ea',
                                      'verb': 'ASCRIBESPOOL01EDITIONS10'},
                                    {'action': 'REGISTER',
                                     'edition_number': 0,
                                     'from_address': u'mqXz83H4LCxjf2ie8hYNsTRByvtfV43Pa7',
                                     'number_editions': 10,
                                     'piece_address': u'myr2VcDnPKf997sjXx6rUFc4CtFH9sxNVS',
                                     'timestamp_utc': 1432651005,
                                     'to_address': u'n2sQHoUghWUgSM8msqdmCim8pZ635YjoCD',
                                     'txid': u'02994a3ceee87be2210fa6e4a649bc0626e791f590bd8db22e7e1fd9fc66d038',
                                     'verb': 'ASCRIBESPOOL01REGISTER0'}]})
Exemplo n.º 8
0
 def test_data(self):
     tree = self.tree
     data = {0: BlockchainSpider.chain(tree, 0)}
     self.assertDictEqual(data, {0: [{'action': 'EDITIONS',
                                      'edition_number': 0,
                                      'from_address': u'mqXz83H4LCxjf2ie8hYNsTRByvtfV43Pa7',
                                      'number_editions': 10,
                                      'piece_address': u'myr2VcDnPKf997sjXx6rUFc4CtFH9sxNVS',
                                      'timestamp_utc': 1432649855,
                                      'to_address': u'n2sQHoUghWUgSM8msqdmCim8pZ635YjoCD',
                                      'txid': u'fb22bbb83161f6904f1803ee1cdbed1b5836eb9ac51b102564400989780b48ea',
                                      'verb': 'ASCRIBESPOOL01EDITIONS10'},
                                    {'action': 'REGISTER',
                                     'edition_number': 0,
                                     'from_address': u'mqXz83H4LCxjf2ie8hYNsTRByvtfV43Pa7',
                                     'number_editions': 10,
                                     'piece_address': u'myr2VcDnPKf997sjXx6rUFc4CtFH9sxNVS',
                                     'timestamp_utc': 1432651005,
                                     'to_address': u'n2sQHoUghWUgSM8msqdmCim8pZ635YjoCD',
                                     'txid': u'02994a3ceee87be2210fa6e4a649bc0626e791f590bd8db22e7e1fd9fc66d038',
                                     'verb': 'ASCRIBESPOOL01REGISTER0'}]})
Exemplo n.º 9
0
 def test_check_scripts(self):
     t = Transactions(testnet=True)
     tx = t.get(TXID)
     vouts = tx['vouts']
     verb = BlockchainSpider.check_script(vouts)
     self.assertEqual(verb, 'ASCRIBESPOOL01EDITIONS10')
Exemplo n.º 10
0
 def test_decode_op_return(self):
     decoded_op_return = BlockchainSpider.decode_op_return(OP_RETURN_HEX)
     self.assertEqual(decoded_op_return, 'ASCRIBESPOOL01LOAN1/150522150523')
Exemplo n.º 11
0
 def setUpClass(cls):
     bcs = BlockchainSpider(testnet=True)
     cls.tree = bcs.history(PIECE_HASH)
Exemplo n.º 12
0
    def test_spool(self):
        # 1. Refill Federation wallet with necessary fuel and tokens
        print
        print 'Refilling Federation wallet with necessary fuel and tokens'
        txid = self.spool.refill_main_wallet(self.refill_root, self.federation_root[1], 7, 11, self.refill_pass,
                                             min_confirmations=1, sync=True)
        print txid

        # 2. user1 registers master edition
        print
        print 'user1 registers master edition'
        txid = self.spool.register(self.federation_root, self.user1_root[1], self.file_hash,
                                   self.federation_pass, 0, min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01REGISTER0')

        # 3. user1 registers number of editions
        print
        print 'user1 registers number of editions'
        txid = self.spool.editions(self.federation_root, self.user1_root[1], self.file_hash,
                                   self.federation_pass, 10, min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01EDITIONS10')

        # 4. user1 registers edition number 1
        print
        print 'user1 registers edition number 1'
        txid = self.spool.register(self.federation_root, self.user1_leaf[1], self.file_hash,
                                   self.federation_pass, 1, min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01REGISTER1')

        # 5. Refill user1 wallet before transfer
        print
        print 'Refill user1 wallet before transfer'
        txid = self.spool.refill(self.federation_root, self.user1_leaf[1], 1, 1,
                                 self.federation_pass, min_confirmations=1, sync=True)
        print txid

        # 5. User1 transfers edition number 1 to user2
        print
        print 'User1 transfers edition number 1 to user 2'
        txid = self.spool.transfer(self.user1_leaf, self.user2_leaf[1], self.file_hash,
                                   self.user1_pass, 1, min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01TRANSFER1')

        # 6. Refill user2 wallet before consign
        print
        print 'Refill user2 wallet before consign'
        txid = self.spool.refill(self.federation_root, self.user2_leaf[1], 1, 1,
                                 self.federation_pass, min_confirmations=1, sync=True)
        print txid

        # 6. user2 consigns edition number 1 to user3
        print
        print 'user2 consigns edition number 1 to user3'
        txid = self.spool.consign(self.user2_leaf, self.user3_leaf[1], self.file_hash,
                                  self.user2_pass, 1, min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01CONSIGN1')

        # 7. Refill user3 wallet before unconsign
        print
        print 'Refill user3 wallet before unconsign'
        txid = self.spool.refill(self.federation_root, self.user3_leaf[1], 1, 1,
                                 self.federation_pass, min_confirmations=1, sync=True)
        print txid

        # 7. user3 unconsigns edition number 1 to user2
        print
        print 'user3 unconsigns edition number 1 back to user2'
        txid = self.spool.unconsign(self.user3_leaf, self.user2_leaf[1], self.file_hash,
                                    self.user3_pass, 1, min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01UNCONSIGN1')

        # 8. Refill user2 wallet before loan
        print
        print 'Refill user2 wallet before loan'
        txid = self.spool.refill(self.federation_root, self.user2_leaf[1], 1, 1,
                                 self.federation_pass, min_confirmations=1, sync=True)
        print txid

        # 8. user2 loans edition number 1 to user3
        print
        print 'user2 loans edition number 1 to user3'
        txid = self.spool.loan(self.user2_leaf, self.user3_leaf[1], self.file_hash,
                               self.user2_pass, 1, '150522', '150523', min_confirmations=1, sync=True)
        print txid

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01LOAN1/150522150523')
Exemplo n.º 13
0
 def test_check_scripts(self):
     t = Transactions(testnet=True)
     tx = t.get(TXID)
     vouts = tx['vouts']
     verb = BlockchainSpider.check_script(vouts)
     self.assertEqual(verb, b'ASCRIBESPOOL01EDITIONS10')
Exemplo n.º 14
0
 def test_decode_op_return(self):
     decoded_op_return = BlockchainSpider.decode_op_return(OP_RETURN_HEX)
     self.assertEqual(decoded_op_return, b'ASCRIBESPOOL01LOAN1/150522150523')
Exemplo n.º 15
0
 def setUpClass(cls):
     bcs = BlockchainSpider(testnet=True)
     cls.tree = bcs.history(PIECE_HASH)
Exemplo n.º 16
0
    def test_spool(self):
        # 1. Refill Federation wallet with necessary fuel and tokens
        print()
        print('Refilling Federation wallet with necessary fuel and tokens')
        txid = self.spool.refill_main_wallet(self.refill_root,
                                             self.federation_root[1],
                                             7,
                                             11,
                                             self.refill_pass,
                                             min_confirmations=1,
                                             sync=True)
        print(txid)

        # 2. user1 registers master edition
        print()
        print('user1 registers master edition')
        txid = self.spool.register(self.federation_root,
                                   self.user1_root[1],
                                   self.file_hash,
                                   self.federation_pass,
                                   0,
                                   min_confirmations=1,
                                   sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01REGISTER0')

        # 3. user1 registers number of editions
        print()
        print('user1 registers number of editions')
        txid = self.spool.editions(self.federation_root,
                                   self.user1_root[1],
                                   self.file_hash,
                                   self.federation_pass,
                                   10,
                                   min_confirmations=1,
                                   sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01EDITIONS10')

        # 4. user1 registers edition number 1
        print()
        print('user1 registers edition number 1')
        txid = self.spool.register(self.federation_root,
                                   self.user1_leaf[1],
                                   self.file_hash,
                                   self.federation_pass,
                                   1,
                                   min_confirmations=1,
                                   sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01REGISTER1')

        # 5. Refill user1 wallet before transfer
        print()
        print('Refill user1 wallet before transfer')
        txid = self.spool.refill(self.federation_root,
                                 self.user1_leaf[1],
                                 1,
                                 1,
                                 self.federation_pass,
                                 min_confirmations=1,
                                 sync=True)
        print(txid)

        # 5. User1 transfers edition number 1 to user2
        print()
        print('User1 transfers edition number 1 to user 2')
        txid = self.spool.transfer(self.user1_leaf,
                                   self.user2_leaf[1],
                                   self.file_hash,
                                   self.user1_pass,
                                   1,
                                   min_confirmations=1,
                                   sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01TRANSFER1')

        # 6. Refill user2 wallet before consign
        print()
        print('Refill user2 wallet before consign')
        txid = self.spool.refill(self.federation_root,
                                 self.user2_leaf[1],
                                 1,
                                 1,
                                 self.federation_pass,
                                 min_confirmations=1,
                                 sync=True)
        print(txid)

        # 6. user2 consigns edition number 1 to user3
        print()
        print('user2 consigns edition number 1 to user3')
        txid = self.spool.consign(self.user2_leaf,
                                  self.user3_leaf[1],
                                  self.file_hash,
                                  self.user2_pass,
                                  1,
                                  min_confirmations=1,
                                  sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01CONSIGN1')

        # 7. Refill user3 wallet before unconsign
        print()
        print('Refill user3 wallet before unconsign')
        txid = self.spool.refill(self.federation_root,
                                 self.user3_leaf[1],
                                 1,
                                 1,
                                 self.federation_pass,
                                 min_confirmations=1,
                                 sync=True)
        print(txid)

        # 7. user3 unconsigns edition number 1 to user2
        print()
        print('user3 unconsigns edition number 1 back to user2')
        txid = self.spool.unconsign(self.user3_leaf,
                                    self.user2_leaf[1],
                                    self.file_hash,
                                    self.user3_pass,
                                    1,
                                    min_confirmations=1,
                                    sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01UNCONSIGN1')

        # 8. Refill user2 wallet before loan
        print()
        print('Refill user2 wallet before loan')
        txid = self.spool.refill(self.federation_root,
                                 self.user2_leaf[1],
                                 1,
                                 1,
                                 self.federation_pass,
                                 min_confirmations=1,
                                 sync=True)
        print(txid)

        # 8. user2 loans edition number 1 to user3
        print()
        print('user2 loans edition number 1 to user3')
        txid = self.spool.loan(self.user2_leaf,
                               self.user3_leaf[1],
                               self.file_hash,
                               self.user2_pass,
                               1,
                               '150522',
                               '150523',
                               min_confirmations=1,
                               sync=True)
        print(txid)

        tx = self.t.get(txid)
        verb = BlockchainSpider.check_script(tx['vouts'])
        self.assertEqual(verb, 'ASCRIBESPOOL01LOAN1/150522150523')