contract must be deployed to the network under some account (owner)
different account (signer) should be set up (using set_signer) for calculating signatures
at least 2 more accounts (user#1, user#2) must be prepared for tests
Tests
Address registration
[x] register_address must fail if at least one of parameters is an empty string ""
[x] register_address must fail if passed eth value is less than passed price_wei
[x] register_address must fail if signature is constructed from incorrect parameters. Signature must be calculated from the following parameters in this order:
msg.sender
name
country
state
city
location
zip
price_wei
confirmation_code_sha3
and signed with signer's private key
[x] specifically check that register_address fails for a case when msg.sender used in signature calculation differs from the actual sender of the transaction
[x] register_address must fail if signature is constructed from correct parameters but signed with different private key (not signer's)
[x] register_address must succeed if all parameters and signature are correct and user#1 didn't register any addresses previously. After this method succeeds, also check:
total_users increased += 1
total_addresses increased += 1
total_confirmed didn't change
users structure has the following element for user#1:
[x] register_address must revert if user#1 tries to register the same address again
[x] register_address must succeed when user#1 registers new address with correct parameters and signature. After this method succeeds, also check that
total_users didn't change
total_addresses increased += 1
total_confirmed didn't change
users structure has the following element for user#1:
{
creation_block: <check that this number didn't change>,
physical_addresses: [
{
<check that the first element didn't change>
},
{
name: <passed name>
country: <passed country>
state: <passed state>
city: <passed city>
location: <passed location>
zip: <passed zip>
creation_block: <new transaction block number>
confirmation_code_sha3: <passed confirmation_code_sha3>
confirmation_block: 0
}
]
}
[x] (use second account user#2) register_address must succeed if all parameters and signature are correct and user#2 didn't register any addresses previously. After this method succeeds, also check:
total_users increased += 1
total_addresses increased += 1
total_confirmed didn't change
users structure has the following element for user#2:
[x] (use second account user#2) register_address must succeed if user#2 registers one of the addresses that user#1 already registered before. After this method succeeds, also check:
total_users didn't change
total_addresses increased += 1
total_confirmed didn't change
users structure has the following element for user#2:
{
creation_block: <check that this number didn't change>,
physical_addresses: [
{
<check that the first element didn't change>
},
{
name: <passed name>
country: <passed country>
state: <passed state>
city: <passed city>
location: <passed location>
zip: <passed zip>
creation_block: <new transaction block number>
confirmation_code_sha3: <passed confirmation_code_sha3>
confirmation_block: 0
}
]
}
Address confirmation
[x] confirm_address must fail if at least one of parameters is an empty string
[x] confirm_address must succeed without payment
[x] confirm_address must fail if signature is constructed from incorrect parameters. Signature must be calculated from the following parameters in this order:
msg.sender
confirmation_code_plain
and signed with signer's private key
[x] specifically check that confirm_address fails for a case when msg.sender used in signature calculation differs from the actual sender of the transaction
[x] confirm_address must fail if signature is constructed from correct parameters but signed with different private key (not signer's)
[x] confirm_address must fail if passed confirmation_code_plain is invalid
[x] confirm_address must succeed if passed confirmation_code_plain is valid. After this method succeeds, also check that
total_users didn't change
total_addresses didn't change
total_confirmed increased += 1
in users structure for the corresponding user, in corresponding element of physical_address array confirmation_block property changed to transaction block number
[x] confirm_address must revert if passed confirmation_code_plain is already confirmed
Withdrawals
[x] withdraw_some must fail if sender of the transaction is not owner
[x] withdraw_some must revert if passed amount_wei is less than contract's balance
[x] withdraw_some must succeed if amount_wei is correct and sender of the transaction is owner. Contract's balance should decrease by amount_wei, owner's balance should increase by amount_wei - gas_fee
[x] withdraw_all must fail if sender of the transaction is not owner
[x] withdraw_all must revert if contract's balance is 0
[x] withdraw_all must succeed if sender of the transaction is owner, contract's balance is not 0. Contract's balance should turn 0, owner's balance should increase by contract_initial_balance - gas_fee
Changing signer
[x] set_signer must fail if sender of the transaction is not owner
[x] set_signer must succeed if sender of the transaction is owner. signer must be updated to the new signer's address. Also check
generate some random data, sign it twice: with an old signer's key and new signer's key, then check that signer_is_valid returns false on the first one and true on the second one
Helpers
[x] user_exists must return true for an existing user, false for a non-existing user
[x] user_address_confirmed must fail if user does not exist
[x] user_address_confirmed must return true for a confirmed address if user exists
[x] user_address_confirmed must return false for unconfirmed address if user exists
[x] user_address_by_creation_block must fail if user does not exist
[x] user_address_by_creation_block must return (false, 0, false) for an existing user if there are no addresses registered at passed creation_block
[x] user_address_by_creation_block must return (true, address_index, false) for an existing user if there is an unconfirmed address registered at passed creation_block
[x] user_address_by_creation_block must return (true, address_index, true) for an existing user if there is a confirmed address registered at passed creation_block
[x] user_address_by_confirmation_code must fail if user does not exist
[x] user_address_by_confirmation_code must return (false, 0, false) for an existing user if there are no addresses with passed confirmation_code_sha3
[x] user_address_by_confirmation_code must return (true, address_index, false) for an existing user if there is an unconfirmed address with passed confirmation_code_sha3
[x] user_address_by_confirmation_code must return (true, address_index, true) for an existing user if there is a confirmed address with passed confirmation_code_sha3
[x] user_address_by_address must fail if user does not exist
[x] user_address_by_address must return (false, 0, false) for an existing user if there is no corresponding address for passed values of country, state, ...
[x] user_address_by_address must return (true, address_index, false) for an existing user if there is an unconfirmed address for passed values of country, state, ...
[x] user_address_by_address must return (true, address_index, true) for an existing user if there is a confirmed address for passed values of country, state, ...
[x] user_last_used_name must fail if user does not exist
[x] user_last_used_name must return name property from the last registered address for an existing user
[x] user_addresses_count must return 0 if user does not exist
[x] user_addresses_count must return number of addresses for an existing user
[x] user_address must fail if user does not exist
[x] user_address must return returns (country, state, city, location, zip) for an existing user
[x] user_address_info must fail if user does not exist
[x] user_address_info must return (name, creation_block, confirmation_block) for an existing user
Prerequisites
owner
)signer
) should be set up (usingset_signer
) for calculating signaturesuser#1
,user#2
) must be prepared for testsTests
register_address
must fail if at least one of parameters is an empty string""
register_address
must fail if passed eth value is less than passedprice_wei
register_address
must fail if signature is constructed from incorrect parameters. Signature must be calculated from the following parameters in this order:msg.sender
name
country
state
city
location
zip
price_wei
confirmation_code_sha3
and signed with
signer
's private keyregister_address
fails for a case whenmsg.sender
used in signature calculation differs from the actual sender of the transactionregister_address
must fail if signature is constructed from correct parameters but signed with different private key (notsigner
's)register_address
must succeed if all parameters and signature are correct anduser#1
didn't register any addresses previously. After this method succeeds, also check:total_users
increased+= 1
total_addresses
increased+= 1
total_confirmed
didn't changeusers
structure has the following element foruser#1
:register_address
must revert ifuser#1
tries to register the same address againregister_address
must succeed whenuser#1
registers new address with correct parameters and signature. After this method succeeds, also check thattotal_users
didn't changetotal_addresses
increased+= 1
total_confirmed
didn't changeusers
structure has the following element foruser#1
:user#2
)register_address
must succeed if all parameters and signature are correct anduser#2
didn't register any addresses previously. After this method succeeds, also check:total_users
increased+= 1
total_addresses
increased+= 1
total_confirmed
didn't changeusers
structure has the following element foruser#2
:user#2
)register_address
must succeed ifuser#2
registers one of the addresses thatuser#1
already registered before. After this method succeeds, also check:total_users
didn't changetotal_addresses
increased+= 1
total_confirmed
didn't changeusers
structure has the following element foruser#2
:confirm_address
must fail if at least one of parameters is an empty stringconfirm_address
must succeed without paymentconfirm_address
must fail if signature is constructed from incorrect parameters. Signature must be calculated from the following parameters in this order:msg.sender
confirmation_code_plain
and signed with
signer
's private keyconfirm_address
fails for a case whenmsg.sender
used in signature calculation differs from the actual sender of the transactionconfirm_address
must fail if signature is constructed from correct parameters but signed with different private key (notsigner
's)confirm_address
must fail if passedconfirmation_code_plain
is invalidconfirm_address
must succeed if passedconfirmation_code_plain
is valid. After this method succeeds, also check thattotal_users
didn't changetotal_addresses
didn't changetotal_confirmed
increased+= 1
users
structure for the corresponding user, in corresponding element ofphysical_address
arrayconfirmation_block
property changed to transaction block numberconfirm_address
must revert if passedconfirmation_code_plain
is already confirmedwithdraw_some
must fail if sender of the transaction is notowner
withdraw_some
must revert if passedamount_wei
is less than contract's balancewithdraw_some
must succeed ifamount_wei
is correct and sender of the transaction isowner
. Contract's balance should decrease byamount_wei
,owner
's balance should increase byamount_wei - gas_fee
withdraw_all
must fail if sender of the transaction is notowner
withdraw_all
must revert if contract's balance is0
withdraw_all
must succeed if sender of the transaction isowner
, contract's balance is not0
. Contract's balance should turn0
,owner
's balance should increase bycontract_initial_balance - gas_fee
Changing signer
set_signer
must fail if sender of the transaction is notowner
set_signer
must succeed if sender of the transaction isowner
.signer
must be updated to the new signer's address. Also checkdata
, sign it twice: with an old signer's key and new signer's key, then check thatsigner_is_valid
returnsfalse
on the first one andtrue
on the second oneHelpers
user_exists
must returntrue
for an existing user,false
for a non-existing user[x]
user_address_confirmed
must fail if user does not exist[x]
user_address_confirmed
must returntrue
for a confirmed address if user exists[x]
user_address_confirmed
must returnfalse
for unconfirmed address if user exists[x]
user_address_by_creation_block
must fail if user does not exist[x]
user_address_by_creation_block
must return(false, 0, false)
for an existing user if there are no addresses registered at passedcreation_block
[x]
user_address_by_creation_block
must return(true, address_index, false)
for an existing user if there is an unconfirmed address registered at passedcreation_block
[x]
user_address_by_creation_block
must return(true, address_index, true)
for an existing user if there is a confirmed address registered at passedcreation_block
[x]
user_address_by_confirmation_code
must fail if user does not exist[x]
user_address_by_confirmation_code
must return(false, 0, false)
for an existing user if there are no addresses with passedconfirmation_code_sha3
[x]
user_address_by_confirmation_code
must return(true, address_index, false)
for an existing user if there is an unconfirmed address with passedconfirmation_code_sha3
[x]
user_address_by_confirmation_code
must return(true, address_index, true)
for an existing user if there is a confirmed address with passedconfirmation_code_sha3
[x]
user_address_by_address
must fail if user does not exist[x]
user_address_by_address
must return(false, 0, false)
for an existing user if there is no corresponding address for passed values of country, state, ...[x]
user_address_by_address
must return(true, address_index, false)
for an existing user if there is an unconfirmed address for passed values of country, state, ...[x]
user_address_by_address
must return(true, address_index, true)
for an existing user if there is a confirmed address for passed values of country, state, ...[x]
user_last_used_name
must fail if user does not exist[x]
user_last_used_name
must returnname
property from the last registered address for an existing user[x]
user_addresses_count
must return0
if user does not exist[x]
user_addresses_count
must return number of addresses for an existing user[x]
user_address
must fail if user does not exist[x]
user_address
must returnreturns (country, state, city, location, zip)
for an existing user[x]
user_address_info
must fail if user does not exist[x]
user_address_info
must return(name, creation_block, confirmation_block)
for an existing user