def test_register_secret_batch_return_value(secret_registry_contract, get_accounts, get_block):
    """ See registerSecret returns True only when all secrets are registered """
    (A,) = get_accounts(1)
    secrets = [fake_bytes(32, '02'), fake_bytes(32, '03'), fake_bytes(11)]

    assert secret_registry_contract.functions.registerSecretBatch(secrets).call() is False

    secrets[2] = fake_bytes(32, '04')
    assert secret_registry_contract.functions.registerSecretBatch(secrets).call() is True

    secret_registry_contract.functions.registerSecret(secrets[1]).transact({'from': A})
    assert secret_registry_contract.functions.registerSecretBatch(secrets).call() is False
Пример #2
0
def test_register_secret_batch_return_value(
    secret_registry_contract: Contract, get_accounts: Callable
) -> None:
    """ See registerSecret returns True only when all secrets are registered """
    (A,) = get_accounts(1)
    secrets = [fake_bytes(32, "02"), fake_bytes(32, "03"), fake_bytes(32)]

    assert secret_registry_contract.functions.registerSecretBatch(secrets).call()

    secrets[2] = fake_bytes(32, "04")
    assert secret_registry_contract.functions.registerSecretBatch(secrets).call() is True

    secret_registry_contract.functions.registerSecret(secrets[1]).call_and_transact({"from": A})
    assert secret_registry_contract.functions.registerSecretBatch(secrets).call() is False
Пример #3
0
def test_register_secret_batch_events(
    secret_registry_contract: Contract, event_handler: Callable
) -> None:
    """ A registerSecretBatch() with three secrets causes three EVENT_SECRET_REVEALED events """
    secrets = [fake_bytes(32, "02"), fake_bytes(32, "03"), fake_bytes(32, "04")]
    secret_hashes = [sha256(secret).digest() for secret in secrets]

    ev_handler = event_handler(secret_registry_contract)

    txn_hash = secret_registry_contract.functions.registerSecretBatch(secrets).call_and_transact()

    ev_handler.add(
        txn_hash, EVENT_SECRET_REVEALED, check_secrets_revealed(secret_hashes, secrets), 3
    )
    ev_handler.check()
def test_register_secret_call(secret_registry_contract, event_handler):
    """ Test the registrable and not registrable secrets """
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret().transact()
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret(3).transact()
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret(0).transact()
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret('').transact()
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret(fake_bytes(33)).transact()

    assert secret_registry_contract.functions.registerSecret(fake_bytes(32)).call() is False
    assert secret_registry_contract.functions.registerSecret(fake_bytes(10, '02')).call() is True
    assert secret_registry_contract.functions.registerSecret(fake_bytes(32, '02')).call() is True
def test_register_secret_batch_events(secret_registry_contract, event_handler):
    """ A registerSecretBatch() with three secrets causes three EVENT_SECRET_REVEALED events """
    secrets = [fake_bytes(32, '02'), fake_bytes(32, '03'), fake_bytes(32, '04')]
    secret_hashes = [Web3.sha3(secret) for secret in secrets]

    ev_handler = event_handler(secret_registry_contract)

    txn_hash = secret_registry_contract.functions.registerSecretBatch(secrets).transact()

    ev_handler.add(
        txn_hash,
        EVENT_SECRET_REVEALED,
        check_secrets_revealed(secret_hashes, secrets),
        3,
    )
    ev_handler.check()
def test_register_secret_call(secret_registry_contract: Contract) -> None:
    """ Test the registrable and not registrable secrets """
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret()
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret(3)
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret(0)
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret("")
    with pytest.raises(ValidationError):
        secret_registry_contract.functions.registerSecret(fake_bytes(33))

    # For interoperability with other SHA256-based hashlocks, even 0x0000..00 needs to be accepted.
    assert secret_registry_contract.functions.registerSecret(fake_bytes(32)).call() is True
    assert secret_registry_contract.functions.registerSecret(fake_bytes(10, "02")).call() is True
    assert secret_registry_contract.functions.registerSecret(fake_bytes(32, "02")).call() is True
def test_register_secret_batch(secret_registry_contract, get_accounts, get_block):
    """ Register four secrets and see them registered """
    (A,) = get_accounts(1)
    secrets = [fake_bytes(32, fill) for fill in ('02', '03', '04', '05')]
    secret_hashes = [Web3.sha3(secret) for secret in secrets]

    for hash in secret_hashes:
        assert secret_registry_contract.functions.getSecretRevealBlockHeight(hash).call() == 0

    txn_hash = secret_registry_contract.functions.registerSecretBatch(secrets).transact({
        'from': A,
    })
    block = get_block(txn_hash)

    for hash in secret_hashes:
        assert secret_registry_contract.functions.getSecretRevealBlockHeight(hash).call() == block
Пример #8
0
def test_register_secret_batch(
    secret_registry_contract: Contract, get_accounts: Callable, get_block: Callable
) -> None:
    """ Register four secrets and see them registered """
    (A,) = get_accounts(1)
    secrets = [fake_bytes(32, fill) for fill in ("02", "03", "04", "05")]
    secret_hashes = [sha256(secret).digest() for secret in secrets]

    for h in secret_hashes:
        assert secret_registry_contract.functions.getSecretRevealBlockHeight(h).call() == 0

    txn_hash = secret_registry_contract.functions.registerSecretBatch(secrets).call_and_transact(
        {"from": A}
    )
    block = get_block(txn_hash)

    for h in secret_hashes:
        assert secret_registry_contract.functions.getSecretRevealBlockHeight(h).call() == block