Skip to content

Commit

Permalink
Faucet (#333)
Browse files Browse the repository at this point in the history
* integrate faucet locally

* benchmarking for faucet and reputation commitments

* implement faucet cli

* implement faucet integration tests

* fix cli and weights

* weights

* clippy

* unpatch pallets

* taplo fmt

* update cargo.lock
  • Loading branch information
pifragile authored Jun 16, 2023
1 parent 1d10049 commit 452b1dd
Show file tree
Hide file tree
Showing 13 changed files with 1,033 additions and 130 deletions.
265 changes: 164 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ members = [
]

#only while debugging
#[patch."https://github.com/encointer/pallets"]
#encointer-balances-tx-payment = { path = "../encointer-pallets/balances-tx-payment" }
#encointer-balances-tx-payment-rpc = { path = "../encointer-pallets/balances-tx-payment/rpc" }
#encointer-balances-tx-payment-rpc-runtime-api = { path = "../encointer-pallets/balances-tx-payment/rpc/runtime-api" }
#encointer-ceremonies-assignment = { path = "../encointer-pallets/ceremonies/assignment" }
#encointer-primitives = { path = "../encointer-pallets/primitives" }
#pallet-encointer-balances = { path = "../encointer-pallets/balances" }
#pallet-encointer-bazaar = { path = "../encointer-pallets/bazaar" }
#pallet-encointer-bazaar-rpc = { path = "../encointer-pallets/bazaar/rpc" }
#pallet-encointer-bazaar-rpc-runtime-api = { path = "../encointer-pallets/bazaar/rpc/runtime-api" }
#pallet-encointer-ceremonies = { path = "../encointer-pallets/ceremonies" }
#pallet-encointer-ceremonies-rpc = { path = "../encointer-pallets/ceremonies/rpc" }
#pallet-encointer-ceremonies-rpc-runtime-api = { path = "../encointer-pallets/ceremonies/rpc/runtime-api" }
#pallet-encointer-communities = { path = "../encointer-pallets/communities" }
#pallet-encointer-communities-rpc = { path = "../encointer-pallets/communities/rpc" }
#pallet-encointer-communities-rpc-runtime-api = { path = "../encointer-pallets/communities/rpc/runtime-api" }
#pallet-encointer-scheduler = { path = "../encointer-pallets/scheduler" }
[patch."https://github.com/encointer/pallets"]
# encointer-balances-tx-payment = { path = "../encointer-pallets/balances-tx-payment" }
# encointer-balances-tx-payment-rpc = { path = "../encointer-pallets/balances-tx-payment/rpc" }
# encointer-balances-tx-payment-rpc-runtime-api = { path = "../encointer-pallets/balances-tx-payment/rpc/runtime-api" }
# encointer-ceremonies-assignment = { path = "../encointer-pallets/ceremonies/assignment" }
# encointer-primitives = { path = "../encointer-pallets/primitives" }
# pallet-encointer-balances = { path = "../encointer-pallets/balances" }
# pallet-encointer-bazaar = { path = "../encointer-pallets/bazaar" }
# pallet-encointer-bazaar-rpc = { path = "../encointer-pallets/bazaar/rpc" }
# pallet-encointer-bazaar-rpc-runtime-api = { path = "../encointer-pallets/bazaar/rpc/runtime-api" }
# pallet-encointer-ceremonies = { path = "../encointer-pallets/ceremonies" }
# pallet-encointer-ceremonies-rpc = { path = "../encointer-pallets/ceremonies/rpc" }
# pallet-encointer-ceremonies-rpc-runtime-api = { path = "../encointer-pallets/ceremonies/rpc/runtime-api" }
# pallet-encointer-communities = { path = "../encointer-pallets/communities" }
# pallet-encointer-communities-rpc = { path = "../encointer-pallets/communities/rpc" }
# pallet-encointer-communities-rpc-runtime-api = { path = "../encointer-pallets/communities/rpc/runtime-api" }
# pallet-encointer-faucet = { path = "../encointer-pallets/faucet" }
# pallet-encointer-reputation-commitments = { path = "../encointer-pallets/reputation-commitments" }
# pallet-encointer-scheduler = { path = "../encointer-pallets/scheduler" }

# [patch."https://github.com/scs/substrate-api-client"]
# substrate-api-client = { path = "../substrate-api-client" }
Expand Down
66 changes: 66 additions & 0 deletions client/bootstrap_demo_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,70 @@ def test_endorsements_by_reputables(client, cid):
# endorsee count is still 5
check_participant_count(client, cid, "Endorsee", 5)

def balance(x):
return x * 10**12


def test_faucet(client, cid):
client.set_faucet_reserve_amount("//Alice", balance(3000))
client.await_block(2)
balance_bob = client.balance("//Bob")
client.create_faucet("//Bob", "TestFaucet", balance(10000), balance(1000), [cid], cid=cid, pay_fees_in_cc=True)
client.await_block(2)
faucet_account = "5CRaq3MpDT1j1d7xoaG3LDwqgC5AoTzRtGptSHm2yFrWoVid"
print(client.balance("//Bob"), flush=True)
print(balance_bob, flush=True)
print(client.balance(faucet_account), flush=True)
if(not client.balance(faucet_account) == balance(10000)):
print(f"Wrong Faucet balance after faucet creation")
exit(1)
if(not balance_bob - client.balance("//Bob") == balance(13000)):
print(f"Wrong Bob balance after faucet creation")
exit(1)
print('Faucet created', flush=True)

balance_charlie = client.balance("//Charlie")
client.drip_faucet("//Charlie", faucet_account, 1, cid=cid, pay_fees_in_cc=True)
client.await_block(2)
if(not client.balance("//Charlie") == balance_charlie + balance(1000)):
print(f"Drip failed")
exit(1)
print('Faucet dripped', flush=True)

balance_bob = client.balance("//Bob")
client.dissolve_faucet("//Alice", faucet_account, "//Eve")
client.await_block(2)

if(not client.balance("//Eve") == balance(9000)):
print(f"Dissolve failed")
exit(1)

if(not client.balance("//Bob") == balance_bob + balance(3000)):
print(f"Dissolve failed")
exit(1)

print('Faucet dissolved', flush=True)
client.create_faucet("//Bob", "TestFaucet", balance(10000), balance(9000), [cid], cid=cid, pay_fees_in_cc=True)
client.await_block(2)
if(not client.balance(faucet_account) == balance(10000)):
print(f"Faucet creation failed")
exit(1)
print('Faucet created', flush=True)
client.drip_faucet("//Charlie", faucet_account, 1, cid=cid, pay_fees_in_cc=True)
client.await_block(2)
print('Faucet dripped', flush=True)
balance_bob = client.balance("//Bob")
client.close_faucet("//Bob", faucet_account, cid=cid, pay_fees_in_cc=True)
client.await_block(2)
if(not client.balance(faucet_account) == 0):
print(f"Faucet closing failed with wrong faucet balance")
exit(1)

if(not client.balance("//Bob") == balance_bob + balance(3000)):
print(f"Faucet closing failed with wrong bob balance")
exit(1)
print('Faucet closed', flush=True)

@click.command()
@click.option('--client', default='../target/release/encointer-client-notee', help='Client binary to communicate with the chain.')
@click.option('-u', '--url', default='ws://127.0.0.1', help='URL of the chain.')
Expand Down Expand Up @@ -312,6 +376,8 @@ def main(ipfs_local, client, url, port, spec_file, test):
print("claim_reward fees were not refunded if paid in cc")
exit(1)

test_faucet(client, cid)

fee_payment_transfers(client, cid)

test_reputation_caching(client, cid, accounts)
Expand Down
20 changes: 20 additions & 0 deletions client/py_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,23 @@ def transfer(self, cid, source, dest, amount, pay_fees_in_cc=False):
def purge_community_ceremony(self, cid, from_cindex, to_cindex, pay_fees_in_cc=False):
ret = self.run_cli_command(["purge-community-ceremony", str(from_cindex), str(to_cindex)], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def create_faucet(self, account, facuet_name, amount, drip_amount, whitelist, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["create-faucet", account, facuet_name, str(amount), str(drip_amount)] + whitelist, cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def drip_faucet(self, account, facuet_account, cindex, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["drip-faucet", account, facuet_account, str(cindex)], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def dissolve_faucet(self, account, facuet_account, beneficiary, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["dissolve-faucet", "--signer", account, facuet_account, beneficiary], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def close_faucet(self, account, facuet_account, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["close-faucet", account, facuet_account], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()

def set_faucet_reserve_amount(self, account, amount, cid=None, pay_fees_in_cc=False):
ret = self.run_cli_command(["set-faucet-reserve-amount", "--signer", account, str(amount)], cid, pay_fees_in_cc)
return ret.stdout.decode("utf-8").strip()
Loading

0 comments on commit 452b1dd

Please sign in to comment.