예제 #1
0
 def test_is_tx_valid_negative(self, *mocks):
     """Test is_tx_valid init negative result."""
     ledger_apis = LedgerApis(
         {ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG},
         FETCHAI,
     )
     result = ledger_apis.is_tx_valid(
         FETCHAI, "tx_digest", "seller", "client", "tx_nonce", 1
     )
     assert not result
예제 #2
0
    def test_validate_ethereum_transaction(self):
        seller = EthereumCrypto()
        client = EthereumCrypto()
        ledger_apis = LedgerApis(
            {ETHEREUM: DEFAULT_ETHEREUM_CONFIG, FETCHAI: DEFAULT_FETCHAI_CONFIG},
            FETCHAI,
        )
        tx_nonce = ledger_apis.generate_tx_nonce(
            ETHEREUM, seller.address, client.address
        )

        tx_digest = "0xbefa7768c313ff49bf274eefed001042a0ff9e3cfbe75ff1a9c2baf18001cec4"
        result = AttributeDict(
            {
                "blockHash": HexBytes(
                    "0x0bfc237d2a17f719a3300a4822779391ec6e3a74832fe1b05b8c477902b0b59e"
                ),
                "blockNumber": 7161932,
                "from": client.address,
                "gas": 200000,
                "gasPrice": 50000000000,
                "hash": HexBytes(
                    "0xbefa7768c313ff49bf274eefed001042a0ff9e3cfbe75ff1a9c2baf18001cec4"
                ),
                "input": tx_nonce,
                "nonce": 4,
                "r": HexBytes(
                    "0xb54ce8b9fa1d1be7be316c068af59a125d511e8dd51202b1a7e3002dee432b52"
                ),
                "s": HexBytes(
                    "0x4f44702b3812d3b4e4b76da0fd5b554b3ae76d1717db5b6b5faebd7b85ae0303"
                ),
                "to": seller.address,
                "transactionIndex": 0,
                "v": 42,
                "value": 2,
            }
        )
        with mock.patch.object(
            ledger_apis.apis.get(ETHEREUM).api.eth,
            "getTransaction",
            return_value=result,
        ):
            assert ledger_apis.is_tx_valid(
                identifier=ETHEREUM,
                tx_digest=tx_digest,
                seller=seller.address,
                client=client.address,
                tx_nonce=tx_nonce,
                amount=2,
            )
예제 #3
0
    def test_validate_transaction_fetchai(self):
        """Test the validate transaction for fetchai ledger."""
        seller_crypto = FetchAICrypto()
        client_crypto = FetchAICrypto()
        ledger_apis = LedgerApis(
            {
                ETHEREUM: DEFAULT_ETHEREUM_CONFIG,
                FETCHAI: DEFAULT_FETCHAI_CONFIG
            },
            FETCHAI,
        )

        seller_address = str(seller_crypto.address)
        client_address = str(client_crypto.address)
        tx_contents = TxContents(
            digest=b"digest",
            action="action",
            chain_code="1",
            from_address=client_address,
            contract_digest="Contract_digest",
            contract_address=None,
            valid_from=1,
            valid_until=6,
            charge=10,
            charge_limit=2,
            transfers=[{
                "to": seller_address,
                "amount": 100
            }],
            signatories=["signatories"],
            data="data",
        )

        with mock.patch.object(ledger_apis.apis.get(FETCHAI)._api.tx,
                               "contents",
                               return_value=tx_contents):
            with mock.patch.object(
                    ledger_apis.apis.get(FETCHAI),
                    "is_transaction_settled",
                    return_value=True,
            ):
                result = ledger_apis.is_tx_valid(
                    identifier=FETCHAI,
                    tx_digest="transaction_digest",
                    seller=seller_address,
                    client=client_address,
                    tx_nonce="tx_nonce",
                    amount=100,
                )
                assert result