def test_add_another_source(self):
        now = pytezos.now()
        initial_storage = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'refundTime': format_timestamp(now + 6 * 3600),
                'tokenAddress': f'{fa_address}%transfer',
                'totalAmount': 1000,
                'payoffAmount': 10
            }
        }

        res = self.atomex \
            .add(hashedSecret=hashed_secret, addAmount=100) \
            .result(storage=initial_storage, source=another_source)

        big_map_diff = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'payoffAmount': 10,
                'totalAmount': 1100,
                'refundTime': format_timestamp(now + 6 * 3600),
                'tokenAddress': f'{fa_address}%transfer'
            }
        }
        self.assertDictEqual(big_map_diff, res.big_map_diff)
        self.assertEqual(1, len(res.operations))
        self.assertTransfer(
            src=another_source,
            dst=res.operations[0]['source'],  # Atomex address
            amount=100,
            parameters=res.operations[0]['parameters'])
Example #2
0
    def test_initiate_proxy(self):
        now = pytezos.now()

        res = self.atomex \
            .initiate(participant=party,
                      hashed_secret=hashed_secret,
                      refund_time=now + 6 * 3600,
                      payoff=Decimal('0.02')) \
            .with_amount(Decimal('1')) \
            .result(storage=empty_storage,
                    sender=proxy,
                    source=source)

        big_map_diff = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'amount': Decimal('0.98'),
                'refund_time': format_timestamp(now + 6 * 3600),
                'payoff': Decimal('0.02')
            }
        }
        self.assertDictEqual(big_map_diff, res.big_map_diff)
        self.assertIsInstance(res.storage[0], int)
        self.assertIsNone(res.storage[1])
        self.assertEqual([], res.operations)
Example #3
0
    def test_redeem_by_third_party(self):
        now = pytezos.now()
        initial_storage = [{
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'amount': Decimal('0.98'),
                'refund_time': format_timestamp(now + 60),
                'payoff': Decimal('0.02')
            }
        }, None]

        res = self.atomex \
            .redeem(secret) \
            .result(storage=initial_storage, source=source)

        self.assertDictEqual({hashed_secret: None}, res.big_map_diff)
        self.assertEqual(2, len(res.operations))

        redeem_tx = res.operations[0]
        self.assertEqual(party, redeem_tx['destination'])
        self.assertEqual('980000', redeem_tx['amount'])

        payoff_tx = res.operations[1]
        self.assertEqual(source, payoff_tx['destination'])
        self.assertEqual('20000', payoff_tx['amount'])
Example #4
0
    def test_initiate_proxy(self):
        now = pytezos.now()
        res = self.atomex \
            .initiate(hashedSecret=hashed_secret,
                      participant=party,
                      refundTime=now + 6 * 3600,
                      tokenAddress=fa_address,
                      totalAmount=1000,
                      payoffAmount=10) \
            .result(storage=empty_storage,
                    sender=proxy,
                    source=source)

        big_map_diff = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'payoffAmount': 10,
                'totalAmount': 1000,
                'refundTime': format_timestamp(now + 6 * 3600),
                'tokenAddress': fa_address
            }
        }
        self.assertDictEqual(big_map_diff, res.big_map_diff)
        self.assertEqual(empty_storage, res.storage)
        self.assertEqual(1, len(res.operations))
        self.assertTransfer(src=source,
                            dst=res.operations[0]['source'],
                            amount=1000,
                            parameters=res.operations[0]['parameters'])
Example #5
0
    def test_third_party_refund(self):
        now = pytezos.now()
        initial_storage = {
            '0': {
                hashed_secret: {
                    'initiator': source,
                    'participant': party,
                    'refundTime': format_timestamp(now - 60),
                    'tokenAddress': fa_address,
                    'totalAmount': 1000,
                    'payoffAmount': 10
                }
            },
            '1': None
        }

        res = self.atomex \
            .refund(hashed_secret) \
            .result(storage=initial_storage, source=party)

        self.assertDictEqual({hashed_secret: None}, res.big_map_diff)
        self.assertEqual(1, len(res.operations))
        self.assertTransfer(src=res.operations[0]['source'],
                            dst=source,
                            amount=1000,
                            parameters=res.operations[0]['parameters'])
Example #6
0
    def test_initiate_same_secret(self):
        now = pytezos.now()
        initial_storage = {
            '0': {
                hashed_secret: {
                    'initiator': source,
                    'participant': party,
                    'refundTime': format_timestamp(now + 6 * 3600),
                    'tokenAddress': fa_address,
                    'totalAmount': 1000,
                    'payoffAmount': 0
                }
            },
            '1': None
        }

        with self.assertRaises(MichelsonRuntimeError):
            self.atomex \
                .initiate(hashedSecret=hashed_secret,
                          participant=party,
                          refundTime=now + 6 * 3600,
                          tokenAddress=fa_address,
                          totalAmount=1000,
                          payoffAmount=0) \
                .result(storage=initial_storage,
                        source=source)
    def test_redeem_by_third_party(self):
        now = pytezos.now()
        initial_storage = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'refundTime': format_timestamp(now + 6 * 3600),
                'tokenAddress': f'{fa_address}%transfer',
                'totalAmount': 1000,
                'payoffAmount': 10
            }
        }

        res = self.atomex \
            .redeem(secret) \
            .result(storage=initial_storage, source=source)

        self.assertDictEqual({hashed_secret: None}, res.big_map_diff)
        self.assertEqual(2, len(res.operations))
        self.assertTransfer(src=res.operations[0]['source'],
                            dst=party,
                            amount=990,
                            parameters=res.operations[0]['parameters'])
        self.assertTransfer(src=res.operations[0]['source'],
                            dst=source,
                            amount=10,
                            parameters=res.operations[1]['parameters'])
Example #8
0
    def test_refund_before_expiration(self):
        now = pytezos.now()
        initial_storage = [{
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'amount': Decimal('0.98'),
                'refund_time': format_timestamp(now + 60),
                'payoff': Decimal('0.02')
            }
        }, None]

        with self.assertRaises(MichelsonRuntimeError):
            self.atomex \
                .refund(hashed_secret) \
                .result(storage=initial_storage, source=source)
    def test_add_after_expiration(self):
        now = pytezos.now()
        initial_storage = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'refundTime': format_timestamp(now - 60),
                'tokenAddress': f'{fa_address}%transfer',
                'totalAmount': 1000,
                'payoffAmount': 10
            }
        }

        with self.assertRaises(MichelsonRuntimeError):
            self.atomex \
                .add(hashedSecret=hashed_secret, addAmount=100) \
                .result(storage=initial_storage, source=source)
Example #10
0
    def test_redeem_invalid_secret(self):
        now = pytezos.now()
        initial_storage = {
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'refundTime': format_timestamp(now - 60),
                'tokenAddress': f'{fa_address}%transfer',
                'totalAmount': 1000,
                'payoffAmount': 10
            }
        }

        with self.assertRaises(MichelsonRuntimeError):
            self.atomex \
                .redeem('a' * 32) \
                .result(storage=initial_storage, source=source)
Example #11
0
    def test_add_another_address(self):
        now = pytezos.now()
        initial_storage = [{
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'amount': Decimal('0.98'),
                'refund_time': format_timestamp(now + 6 * 3600),
                'payoff': Decimal('0.02')
            }
        }, None]

        res = self.atomex \
            .add(hashed_secret) \
            .with_amount(Decimal('1')) \
            .result(storage=initial_storage, source=party)

        big_map_diff = initial_storage[0]
        big_map_diff[hashed_secret]['amount'] = Decimal('1.98')
        self.assertDictEqual(big_map_diff, res.big_map_diff)
Example #12
0
    def test_refund_before_expiration(self):
        now = pytezos.now()
        initial_storage = {
            '0': {
                hashed_secret: {
                    'initiator': source,
                    'participant': party,
                    'refundTime': format_timestamp(now + 60),
                    'tokenAddress': fa_address,
                    'totalAmount': 1000,
                    'payoffAmount': 10
                }
            },
            '1': None
        }

        with self.assertRaises(MichelsonRuntimeError):
            self.atomex \
                .refund(hashed_secret) \
                .result(storage=initial_storage, source=source)
Example #13
0
    def test_initiate_same_secret(self):
        now = pytezos.now()
        initial_storage = [{
            hashed_secret: {
                'initiator': source,
                'participant': party,
                'amount': Decimal('0.98'),
                'refund_time': format_timestamp(now + 6 * 3600),
                'payoff': Decimal('0.02')
            }
        }, None]

        with self.assertRaises(MichelsonRuntimeError):
            self.atomex \
                .initiate(participant=party,
                          hashed_secret=hashed_secret,
                          refund_time=now + 6 * 3600,
                          payoff=Decimal('0.02')) \
                .with_amount(Decimal('1')) \
                .result(storage=initial_storage,
                        source=source)
Example #14
0
 def test_now_zeronet(self):
     contract = ContractInterface.create_from(code, shell='zeronet')
     now = format_timestamp(pytezos.using('zeronet').now())
     res = contract.call().result(storage=0)
     self.assertEqual(now, res.storage)
Example #15
0
 def test_now_babylonnet(self):
     contract = ContractInterface.create_from(code)
     now = format_timestamp(pytezos.now())
     res = contract.call().result(storage=0)
     self.assertEqual(now, res.storage)
Example #16
0
 def test_now(self):
     res = self.ci.call().result(storage=0)
     now = format_timestamp(pytezos.now())
     self.assertEqual(now, res.storage)