def test_web_api_transaction(self): # Test _handletxnrequest local_node = self._create_node(8802) gossip = Gossip(local_node) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(gossip, data_directory=path, genesis_ledger=True) validator = TestValidator(ledger) transaction_page = TransactionPage(validator) # TransactionBlock to the ledger txns = [] i = 0 while i < 10: txn = Transaction() txn.sign_from_node(local_node) txns += [txn.Identifier] ledger.TransactionStore[txn.Identifier] = txn i += 1 trans_block = self._create_tblock(local_node, 0, common.NullIdentifier, txns) ledger.BlockStore[trans_block.Identifier] = trans_block ledger.handle_advance(trans_block) # GET /transaction request = self._create_get_request("/transaction/", {}) r = transaction_page.do_get(request) print request.path, r r = r[1:-1].replace('"', "") r = r.replace(" ", "").split(",") self.assertEquals(r, txns) # GET /transaction?blockcount=1 request = self._create_get_request("/transaction", {"blockcount": [1]}) r = transaction_page.do_get(request) r = r[1:-1].replace('"', "") r = r.replace(" ", "").split(",") self.assertEquals(r, txns) # Returns None if testing # GET /transaction/{TransactionID} request = self._create_get_request("/transaction/" + txns[1], {}) txn = ledger.TransactionStore[txns[1]] tinfo = txn.dump() tinfo['Identifier'] = txn.Identifier tinfo['Status'] = txn.Status if txn.Status == tStatus.committed: tinfo['InBlock'] = txn.InBlock self.assertEquals(yaml.load(transaction_page.do_get(request)), tinfo) # GET /transaction/{TransactionID{}/InBlock request = self._create_get_request("/transaction/" + txns[1] + "/InBlock", {}) self.assertEquals(transaction_page.do_get(request).replace('"', ""), txn.InBlock)
def test_web_api_transaction(self): # Test _handletxnrequest LocalNode = self._create_node(8802) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(LocalNode, DataDirectory=path, GenesisLedger=True) validator = TestValidator(ledger) root = RootPage(validator) # TransactionBlock to the ledger txns = [] i = 0 while i < 10: txn = Transaction() txn.sign_from_node(LocalNode) txns += [txn.Identifier] ledger.TransactionStore[txn.Identifier] = txn i += 1 transBlock = self._create_tblock(LocalNode, 0, common.NullIdentifier, txns) ledger.BlockStore[transBlock.Identifier] = transBlock ledger.handle_advance(transBlock) request = self._create_get_request("/transaction", {}) # GET /transaction request = self._create_get_request("/transaction", {}) r = root.do_get(request) r = r[1:-1].replace('"', "") r = r.replace(" ", "").split(",") self.assertEquals(r, txns) # GET /transaction?blockcount=1 request = self._create_get_request("/transaction", {"blockcount": [1]}) r = root.do_get(request) r = r[1:-1].replace('"', "") r = r.replace(" ", "").split(",") self.assertEquals(r, txns) # Returns None if testing # GET /transaction/{TransactionID} request = self._create_get_request("/transaction/" + txns[1], {}) txn = ledger.TransactionStore[txns[1]] tinfo = txn.dump() tinfo['Identifier'] = txn.Identifier tinfo['Status'] = txn.Status if txn.Status == tStatus.committed: tinfo['InBlock'] = txn.InBlock self.assertEquals(yaml.load(root.do_get(request)), tinfo) # GET /transaction/{TransactionID{}/InBlock request = self._create_get_request("/transaction/" + txns[1] + "/InBlock", {}) self.assertEquals(root.do_get(request).replace('"', ""), txn.InBlock)
def test_web_api_block(self): # Test _handleblkrequest local_node = self._create_node(8801) gossip = Gossip(local_node) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(gossip, data_directory=path, genesis_ledger=True) validator = TestValidator(ledger) block_page = BlockPage(validator) # TransactionBlock to the ledger trans_block = self._create_tblock(local_node, 0, common.NullIdentifier, []) trans_block2 = self._create_tblock(local_node, 1, trans_block.Identifier, []) ledger.BlockStore[trans_block.Identifier] = trans_block ledger.BlockStore[trans_block2.Identifier] = trans_block2 ledger.handle_advance(trans_block) ledger.handle_advance(trans_block2) # GET /block request = self._create_get_request("/block", {}) string = '["' + str(trans_block2.Identifier) + '", "' + \ str(trans_block.Identifier) + '"]' self.assertEquals(block_page.do_get(request), string) # GET /block?blockcount=2 request = self._create_get_request("/block", {"blockcount": [2]}) self.assertEquals(block_page.do_get(request), string) # GET /block?blockcount=1 string = '["' + str(trans_block2.Identifier) + '"]' request = self._create_get_request("/block", {"blockcount": [1]}) self.assertEquals(block_page.do_get(request), string) # Add identifier to dictionary dict_b = trans_block.dump() dict_b["Identifier"] = trans_block.Identifier # GET /block/{BlockId} request = self._create_get_request("/block/" + trans_block.Identifier, {}) self.assertEquals(yaml.load(block_page.do_get(request)), dict_b) # GET /block/{BlockId}/Signature request = self._create_get_request("/block/" + trans_block.Identifier + "/Signature", {}) self.assertEquals(block_page.do_get(request), '"' + trans_block.Signature + '"')
def test_web_api_block(self): # Test _handleblkrequest local_node = self._create_node(8801) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(local_node, DataDirectory=path, GenesisLedger=True) validator = TestValidator(ledger) block_page = BlockPage(validator) # TransactionBlock to the ledger trans_block = self._create_tblock(local_node, 0, common.NullIdentifier, []) trans_block2 = self._create_tblock(local_node, 1, trans_block.Identifier, []) ledger.BlockStore[trans_block.Identifier] = trans_block ledger.BlockStore[trans_block2.Identifier] = trans_block2 ledger.handle_advance(trans_block) ledger.handle_advance(trans_block2) # GET /block request = self._create_get_request("/block", {}) string = '["' + str(trans_block2.Identifier) + '", "' + \ str(trans_block.Identifier) + '"]' self.assertEquals(block_page.do_get(request), string) # GET /block?blockcount=2 request = self._create_get_request("/block", {"blockcount": [2]}) self.assertEquals(block_page.do_get(request), string) # GET /block?blockcount=1 string = '["' + str(trans_block2.Identifier) + '"]' request = self._create_get_request("/block", {"blockcount": [1]}) self.assertEquals(block_page.do_get(request), string) # Add identifier to dictionary dict_b = trans_block.dump() dict_b["Identifier"] = trans_block.Identifier # GET /block/{BlockId} request = self._create_get_request("/block/" + trans_block.Identifier, {}) self.assertEquals(yaml.load(block_page.do_get(request)), dict_b) # GET /block/{BlockId}/Signature request = self._create_get_request("/block/" + trans_block.Identifier + "/Signature", {}) self.assertEquals(block_page.do_get(request), '"' + trans_block.Signature + '"')