Esempio n. 1
0
def test_get_secret():
    secret1 = factories.make_secret()
    secret2 = factories.make_secret()
    secrethash3 = factories.make_keccak_hash()
    secrethash4 = factories.make_keccak_hash()

    lock_state = HashTimeLockState(amount=10,
                                   expiration=10,
                                   secrethash=factories.UNIT_SECRETHASH)
    end_state = factories.create(factories.NettingChannelEndStateProperties())
    end_state = factories.replace(
        end_state,
        secrethashes_to_lockedlocks={secrethash3: lock_state},
        secrethashes_to_unlockedlocks={
            sha3(secret1): UnlockPartialProofState(lock=lock_state,
                                                   secret=secret1)
        },
        secrethashes_to_onchain_unlockedlocks={
            sha3(secret2): UnlockPartialProofState(lock=lock_state,
                                                   secret=secret2)
        },
    )

    assert get_secret(
        end_state,
        sha3(secret1)) == secret1  # known secret from offchain unlock
    assert get_secret(
        end_state,
        sha3(secret2)) == secret2  # known secret from offchain unlock
    assert get_secret(end_state,
                      secrethash3) is None  # known lock but not unlocked yet
    assert get_secret(end_state, secrethash4) is None  # unknown secrethash
Esempio n. 2
0
def test_get_batch_unlock_gain():
    channel_state = factories.create(factories.NettingChannelStateProperties())
    channel_state.our_state = replace(
        channel_state.our_state,
        secrethashes_to_lockedlocks={
            factories.make_keccak_hash(): make_hash_time_lock_state(1),
            factories.make_keccak_hash(): make_hash_time_lock_state(2),
        },
        secrethashes_to_unlockedlocks={
            factories.make_keccak_hash(): make_unlock_partial_proof_state(4)
        },
        secrethashes_to_onchain_unlockedlocks={
            factories.make_keccak_hash(): make_unlock_partial_proof_state(8)
        },
    )
    channel_state.partner_state = replace(
        channel_state.partner_state,
        secrethashes_to_lockedlocks={
            factories.make_keccak_hash(): make_hash_time_lock_state(16)
        },
        secrethashes_to_unlockedlocks={
            factories.make_keccak_hash(): make_unlock_partial_proof_state(32)
        },
        secrethashes_to_onchain_unlockedlocks={
            factories.make_keccak_hash(): make_unlock_partial_proof_state(64),
            factories.make_keccak_hash(): make_unlock_partial_proof_state(128),
        },
    )
    unlock_gain = get_batch_unlock_gain(channel_state)
    assert unlock_gain.from_partner_locks == 192
    assert unlock_gain.from_our_locks == 7
Esempio n. 3
0
    def new_blocks(self, number):
        events = list()

        for _ in range(number):
            block_state_change = Block(
                block_number=self.block_number + 1,
                gas_limit=1,
                block_hash=factories.make_keccak_hash(),
            )
            result = node.state_transition(self.chain_state, block_state_change)
            events.extend(result.events)

            self.block_number += 1
Esempio n. 4
0
    def new_blocks(self, number):
        events = list()

        for _ in range(number):
            block_state_change = Block(
                block_number=self.block_number + 1,
                gas_limit=1,
                block_hash=factories.make_keccak_hash(),
            )
            result = node.state_transition(self.chain_state, block_state_change)
            events.extend(result.events)

            self.block_number += 1
Esempio n. 5
0
    def new_blocks(self, number):
        for _ in range(number):
            block_state_change = Block(
                block_number=self.block_number + 1,
                gas_limit=1,
                block_hash=factories.make_keccak_hash(),
            )
            for client in self.address_to_client.values():
                events = list()
                result = node.state_transition(client.chain_state, block_state_change)
                events.extend(result.events)
            # TODO assert on events

            self.block_number += 1