예제 #1
0
    def test_balance_of_with_custom_salt(self):

        intent_action = self.erc20.balanceOf(self.to)

        contract_address = "0xbbf289d846208c16edc8474705c748aff07732db"

        dependencies = [
            "0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e",
            "0x6b67aac6eda8798297b1591da36a215bfbe1fed666c4676faf5a214d54e9e928"
        ]
        salt = "0x0000000000000000000000000000000000000000000000000000000000000001"

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        dependencies=dependencies,
                        salt=salt,
                        max_gas_price=999999,
                        min_gas_limit=300000,
                        expiration=15)

        self.assertEqual(
            intent.id,
            "0x63bfa4961085e360ff2507256aae202ef05fe1883475eb21456796b81f5a0e58"
        )

        intent.salt = "0x0000000000000000000000000000000000000000000000000000000000000002"

        self.assertEqual(
            intent.id,
            "0x6e78ee9f136303375275ad50c6f0823f5863a148d351552409685a8b491d3a98"
        )
예제 #2
0
    def test_balance_of_with_dependencies(self):
        intent_action = self.erc20.balanceOf(self.to)

        contract_address = "0xbbf289d846208c16edc8474705c748aff07732db"

        dependencies = [
            "0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e"
        ]

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        dependencies=dependencies,
                        expiration=15)

        self.assertEqual(
            intent.id,
            "0x5de183da65683636ad564c80559c6cf68d5c738239f15da75e5a020d039cf7fb"
        )

        new_dependencies = [
            "0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e",
            "0x6b67aac6eda8798297b1591da36a215bfbe1fed666c4676faf5a214d54e9e928"
        ]

        intent.dependencies = new_dependencies

        self.assertEqual(
            intent.id,
            "0x0d42d9890e1c0cca4d56ec5b532e6f7f1597f5cda57a0c1726f0eb25d2bc4a26"
        )
예제 #3
0
    def test_sign_intent(self):
        intent_action = self.erc20.balanceOf(self.to)

        contract_address = "0xbbf289d846208c16edc8474705c748aff07732db"

        dependencies = [
            "0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e",
            "0x6b67aac6eda8798297b1591da36a215bfbe1fed666c4676faf5a214d54e9e928"
        ]

        salt = "0x0000000000000000000000000000000000000000000000000000000000000001"

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        dependencies=dependencies,
                        salt=salt,
                        max_gas_price=999999,
                        min_gas_limit=300000,
                        expiration=15)

        signed_intent = intent.sign(self.credentials)

        expected = {
            'id':
            "0x63bfa4961085e360ff2507256aae202ef05fe1883475eb21456796b81f5a0e58",
            'dependencies': [
                '0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e',
                '0x6b67aac6eda8798297b1591da36a215bfbe1fed666c4676faf5a214d54e9e928'
            ],
            'wallet':
            '0xbbf289d846208c16edc8474705c748aff07732db',
            "tx": {
                'to': '0x2f45b6fb2f28a73f110400386da31044b2e953d4',
                'value': 0,
                'data':
                '0x70a082310000000000000000000000007f5eb5bb5cf88cfcee9613368636f458800e62cb',
                'minGasLimit': 300000,
                'maxGasPrice': 999999,
            },
            'salt':
            '0x0000000000000000000000000000000000000000000000000000000000000001',
            'signer':
            '0x9d7713f5048c270d7c1dBe65F44644F4eA47f774',
            "expiration":
            15,
            'signature': {
                'r':
                '0x6381ad3f9c7a15b4a6bec0d21edef69b571de3a7cd5a03befb11468f2c7e19f4',
                's':
                '0x7c9e94006394b16150150d590a5c3beb06e46978e9b2a7c813199570ad6288bc',
                'v': '0x1b'
            }
        }

        self.maxDiff = None

        self.assertEqual(signed_intent, expected)
예제 #4
0
    def test_transfer(self):
        intent_action = self.ERC20(self.token_address).transfer({
            "_to": "0x009ab4de1234c7066197d6ed75743add3576591f",
            "_value": 4
        })

        intent = Intent(intent_action=intent_action,
                        expiration=1548030494,
                        max_gas_price=10**32,
                        max_gas_limit=0)

        self.assertEqual(
            intent.id(self.wallet),
            "0x47b6c0256967782aafd9b03f042efb7b7bbed07e5bd2f08309ca9d4a17cebb75"
        )
예제 #5
0
    def test_balance_of_with_custom_expiration(self):

        intent_action = self.erc20.balanceOf(self.to)

        contract_address = "0xbbf289d846208c16edc8474705c748aff07732db"

        dependencies = [
            "0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e",
            "0x6b67aac6eda8798297b1591da36a215bfbe1fed666c4676faf5a214d54e9e928"
        ]

        salt = "0x0000000000000000000000000000000000000000000000000000000000000001"

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        dependencies=dependencies,
                        salt=salt,
                        max_gas_price=999999,
                        min_gas_limit=300000,
                        expiration=30)

        self.assertEqual(
            intent.id,
            '0xb525cc7118165ae85c0761ce315a3ad4ab5899793f3c9c1f7804e6aa9fcd8534'
        )
예제 #6
0
def test_relay_with_dependency_and_read_status_success():
    wallet_receiver = Wallet(from_bytes(os.urandom(32)))

    intent_action = ERC20(TEST_ERC20).transfer(wallet_receiver.address, 0)
    intent = Intent(intent_action=intent_action)
    intent.add_dependency(success_intents[0])

    signed_intent = wallet.sign(intent)

    response = signed_intent.relay()

    assert response.status_code == 201 or response.status_code == 200
    assert wait_until(lambda: signed_intent.status()["code"] == "completed",
                      640)
    time.sleep(5)

    assert signed_intent.status()["receipt"]["success"]
    success_intents.append(signed_intent)
    assert signed_intent.status()["receipt"]["result"]["output"][0]
예제 #7
0
    def test_intent_with_dependency(self):
        dependency_signed_intent = self.wallet.sign(
            Intent(
                intent_action=ERC20(
                    "0x6B0F919A5d450Fa5e6283Ff6178dC1FCd195FD2A").transfer(
                        "0x009ab4de1234c7066197d6ed75743add3576591f", 0),
                expiration=10**32,
                max_gas_limit=0,
                max_gas_price=9999999999,
            ))

        intent_action = self.ERC20(self.token_address).transfer({
            "_to":
            "0x009ab4de1234c7066197d6ed75743add3576591f",
            "_value":
            100 * 10**18
        })

        intent = Intent(
            intent_action=intent_action,
            expiration=10**36,
            max_gas_limit=0,
            max_gas_price=9999999999,
        )

        intent.add_dependency(dependency_signed_intent)

        self.assertEqual(
            intent.id(self.wallet),
            "0x4548f83726b36feaa3c5d284d3af30759a341aef4fb93ff85140cdcbfe49f7f8"
        )
예제 #8
0
    def test_balanceoff_with_wallet_generation(self):
        intent_action = self.erc20.balanceOf(self.to)

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        expiration=15)
        self.assertEqual(intent.wallet,
                         '0x8bdd988a19f5c9fb82bd98797ac78c1f48bd5af8')

        self.assertEqual(
            intent.id,
            '0xf914432e0e9739b4ee726c1e52579f6d2e96cacac8bc391d3ffeae579372ade3'
        )
예제 #9
0
    def test_balance_of(self):
        intent_action = self.erc20.balanceOf(self.to)

        contract_address = "0xbbf289d846208c16edc8474705c748aff07732db"

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        expiration=15)

        self.assertEqual(
            intent.id,
            "0x0dd96a883c69dca2fef7de903ed543b2751919592a799902aa84ce7ed6a23479"
        )
예제 #10
0
    def test_transfer(self):
        value = 1

        intent_action = self.erc20.transfer(self.to, value)

        contract_address = "0xDc3914BEd4Fc2E387d0388B2E3868e671c143944"

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        expiration=15)

        self.assertEqual(
            intent.id,
            "0x7935c8f49cb284e1c5c8dd95b3fc6c9cad6519a17555a5f2e43f9aaa31d25a37"
        )
예제 #11
0
def test_relay_and_read_status_error():
    intent_action = CallTestContract(TEST_CONTRACT).fail1()
    intent = Intent(intent_action=intent_action)

    signed_intent = wallet.sign(intent)

    response = signed_intent.relay()

    assert response.status_code == 201 or response.status_code == 200
    assert wait_until(lambda: signed_intent.status()["code"] == "completed",
                      640)
    time.sleep(5)

    assert not signed_intent.status()["receipt"]["success"]
    success_intents.append(signed_intent)
    assert signed_intent.status(
    )["receipt"]["result"]["error"] == "This is the error 1"
예제 #12
0
def test_read_receipt_abi():
    intent_action = Contract(abi_test_contract)(TEST_CONTRACT).call2()
    intent = Intent(intent_action=intent_action,
                    salt=from_bytes(os.urandom(32)))

    signed_intent = wallet.sign(intent)

    response = signed_intent.relay()

    assert response.status_code == 201 or response.status_code == 200
    assert wait_until(lambda: signed_intent.status()["code"] == "completed",
                      640)
    time.sleep(5)

    assert signed_intent.status()["receipt"]["success"]
    success_intents.append(signed_intent)
    assert signed_intent.status(
    )["receipt"]["result"]["output"][0] == "This is the return of the call2"
예제 #13
0
def test_read_receipt_multiple():
    intent_action = CallTestContract(TEST_CONTRACT).call3()
    intent = Intent(intent_action=intent_action,
                    salt=from_bytes(os.urandom(32)))

    signed_intent = wallet.sign(intent)

    response = signed_intent.relay()

    assert response.status_code == 201 or response.status_code == 200
    assert wait_until(lambda: signed_intent.status()["code"] == "completed",
                      640)
    time.sleep(5)

    assert signed_intent.status()["receipt"]["success"]
    success_intents.append(signed_intent)
    assert signed_intent.status(
    )["receipt"]["result"]["output"][0] == wallet.address
    assert signed_intent.status()["receipt"]["result"]["output"][1] == int(
        wallet.address, 16) * 9
예제 #14
0
    def test_balance_of_with_custom_gas_prices(self):
        intent_action = self.erc20.balanceOf(self.to)

        contract_address = "0xbbf289d846208c16edc8474705c748aff07732db"

        dependencies = [
            "0xee2e1b62b008e27a5a3d66352f87e760ed85e723b6834e622f38b626090f536e",
            "0x6b67aac6eda8798297b1591da36a215bfbe1fed666c4676faf5a214d54e9e928"
        ]

        intent = Intent(intent_action=intent_action,
                        signer=self.credentials.get_address(),
                        wallet=contract_address,
                        dependencies=dependencies,
                        max_gas_price=999999,
                        min_gas_limit=300000,
                        expiration=15)

        self.assertEqual(
            intent.id,
            "0x40b7b0871f7b3e25020766c21545be0ef33349a949b6f4b9548387d4d539a110"
        )