def test_kyc_participate_over_payment(chain, kyc_crowdsale, customer, customer_id, kyc_token, private_key, preico_starts_at, pricing, team_multisig): """KYC'ed participant does not fulfill his minimum limit.""" # Check KYC crowdsale is good to go time_travel(chain, kyc_crowdsale.call().startsAt() + 1) wei_value = to_wei(1, "ether") # KYC limits for this participant: 0...1 ETH kyc_payload = pack_kyc_dataframe(customer, customer_id, 0, 10 * 10000) signed_data = sign(kyc_payload, private_key) # Use bad private key kyc_crowdsale.transact({ "from": customer, "value": wei_value, "gas": 2222333 }).buyWithKYCData(kyc_payload, signed_data["v"], signed_data["r_bytes"], signed_data["s_bytes"]) with pytest.raises(TransactionFailed): wei_value = to_wei(10, "ether") kyc_crowdsale.transact({ "from": customer, "value": wei_value, "gas": 2222333 }).buyWithKYCData(kyc_payload, signed_data["v"], signed_data["r_bytes"], signed_data["s_bytes"])
def test_roundtrip_kyc_data(kyc_deserializer, whitelisted_address): """We correctly encode data in Python side and decode it back in the smart contract.""" customer_id = uuid.uuid4() dataframe = pack_kyc_dataframe(whitelisted_address, customer_id, int(0.1 * 10000), int(9999 * 10000)) tuple_value = kyc_deserializer.call().getKYCPayload(dataframe) assert tuple_value[0].lower() == whitelisted_address.lower() assert hex(tuple_value[1]) == "0x" + customer_id.hex assert tuple_value[2] == 1000 assert tuple_value[3] == 99990000
def test_kyc_participate_with_signed_address(chain, kyc_crowdsale, customer, customer_id, kyc_token, private_key, preico_starts_at, pricing, team_multisig): """Buy tokens with a proper KYC payload.""" # Check KYC crowdsale is good to go time_travel(chain, kyc_crowdsale.call().startsAt() + 1) # Check the setup looks good assert kyc_crowdsale.call().getState() == CrowdsaleState.Funding assert kyc_crowdsale.call().isFinalizerSane() assert kyc_crowdsale.call().isPricingSane() assert kyc_crowdsale.call().beneficiary() == team_multisig assert kyc_token.call().transferAgents(team_multisig) == True # Do a test buy for 1 ETH and check it is good token wise wei_value = to_wei(1, "ether") tokens_per_eth = pricing.call().calculatePrice(wei_value, wei_value, 0, customer, 18) assert tokens_per_eth == 10**18 assert kyc_crowdsale.call().getTokensLeft() >= tokens_per_eth assert kyc_token.call().balanceOf(team_multisig) >= tokens_per_eth assert not kyc_crowdsale.call().isBreakingCap(wei_value, tokens_per_eth, wei_value, tokens_per_eth) # KYC limits for this participant: 0...1 ETH kyc_payload = pack_kyc_dataframe(customer, customer_id, 0, 1 * 10000) signed_data = sign(kyc_payload, private_key) kyc_crowdsale.transact({ "from": customer, "value": wei_value, "gas": 2222333 }).buyWithKYCData(kyc_payload, signed_data["v"], signed_data["r_bytes"], signed_data["s_bytes"]) # We got credited assert kyc_token.call().balanceOf(customer) > 0 assert kyc_crowdsale.call().investedAmountOf(customer) == 1 * 10**18 # We have tracked the investor id events = kyc_crowdsale.pastEvents("Invested").get() assert len(events) == 1 e = events[0] assert e["args"]["investor"].lower() == customer.lower() assert e["args"]["weiAmount"] == wei_value assert e["args"]["customerId"] == customer_id.int
def test_roundtrip_kyc_data(kyc_deserializer, whitelisted_address): """We correctly encode data in Python side and decode it back in the smart contract.""" customer_id = uuid.uuid4() dataframe = pack_kyc_dataframe(whitelisted_address, customer_id, int(0.1 * 10000), int(9999 * 10000)) tuple_value = kyc_deserializer.call().getKYCPayload(dataframe) # # Check that the output looks like what we did expect # assert tuple_value[0].lower() == whitelisted_address.lower() # Do a raw integer comparison, because web3.py and UUID disagree about left padding zeroes assert tuple_value[1] == customer_id.int assert tuple_value[2] == 1000 assert tuple_value[3] == 99990000
def test_kyc_participate_bad_signature(chain, kyc_crowdsale, customer, customer_id, kyc_token, private_key, preico_starts_at, pricing, team_multisig): """Investment does not happen with a bad signature..""" # Check KYC crowdsale is good to go time_travel(chain, kyc_crowdsale.call().startsAt() + 1) # Do a test buy for 1 ETH and check it is good token wise wei_value = to_wei(1, "ether") # KYC limits for this participant: 0...1 ETH kyc_payload = pack_kyc_dataframe(customer, customer_id, 0, 1 * 10000) signed_data = sign(kyc_payload, private_key + "x") # Use bad private key with pytest.raises(TransactionFailed): kyc_crowdsale.transact({ "from": customer, "value": wei_value, "gas": 2222333 }).buyWithKYCData(kyc_payload, signed_data["v"], signed_data["r_bytes"], signed_data["s_bytes"])