- create a proxy agent.
from cpchain import chain, config
from cpchain.chain.models import OrderInfo
from cpchain.crypto import RSACipher, get_addr_from_public_key
from cpchain.account import Accounts
w3 = chain.utils.default_w3
bin_path = chain.utils.join_with_root(config.chain.contract_bin_path)
contract_name = config.chain.contract_name
chain.utils.deploy_contract(bin_path, contract_name, w3)
proxyAccount = get_addr_from_public_key(Accounts()[0].public_key)
proxyAgent = chain.agents.ProxyAgent(w3, bin_path, contract_name, account=proxyAccount)
- place an order and confirm it.
buyerAccount = get_addr_from_public_key(Accounts()[1].public_key)
buyerAgent = chain.agents.BuyerAgent(w3, bin_path, contract_name, account=buyerAccount)
sellerAccount = get_addr_from_public_key(Accounts()[2].public_key)
sellerAgent = chain.agents.SellerAgent(w3, bin_path, contract_name, account=sellerAccount)
order_id = 0
time_allowed = 2000
def test_place_order(btrans):
buyer_rsa_pubkey = RSACipher.load_public_key()
order_info = OrderInfo(
desc_hash=bytes([0, 1, 2, 3] * 8),
buyer_rsa_pubkey=buyer_rsa_pubkey,
seller=btrans.web3.toChecksumAddress(sellerAccount),
proxy=btrans.web3.toChecksumAddress(proxyAccount),
secondary_proxy=btrans.web3.toChecksumAddress(proxyAccount),
proxy_value=10,
value=20,
time_allowed=time_allowed
)
global order_id
order_id = btrans.place_order(order_info)
#assert order_id == 1
test_record = btrans.query_order(order_id)
assert test_record[0] == bytes([0, 1, 2, 3] * 8)
assert test_record[2] == btrans.account
# Check state is Created
assert test_record[10] == 0
def test_seller_confirm_order(strans):
strans.confirm_order(order_id)
test_record = strans.query_order(order_id)
assert test_record[10] == 1
test_place_order(buyerAgent)
test_seller_confirm_order(sellerAgent)
- deposit and withdraw. (now optional.)
value = 100
proxyAgent.deposit(value)
proxyAgent.query_deposit()
proxyAgent.withdraw(value)
- check order is ready.(if seller has deposited.)
assert proxyAgent.check_order_is_ready(order_id)
- claim product fetched.(after proxy fetched product.)
proxyAgent.claim_fetched(order_id)
# test if proxyAgent.claim_fetch succeed.
test_record = proxyAgent.query_order(order_id)
assert test_record[10] == 2
- claim product delivered.(after proxy delivered product.)
hash = bytes([1, 2, 3, 4] * 4)
proxyAgent.claim_delivered(order_id, hash)
# test if proxyAgent
test_record = proxyAgent.query_order(order_id)
assert test_record[10] == 3
mode
variable from"dummy"
to"local"
.Thanks a lot!