Skip to content

Commit

Permalink
Integration tests for new features (#269)
Browse files Browse the repository at this point in the history
* test unregister un upgrade registration

* test endorsements by reputables

* fmt

* add test flag to bootstrap_demo_community.py

* bump pallets

* minor fix
  • Loading branch information
pifragile authored Nov 23, 2022
1 parent 9e60397 commit bed1623
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jobs:
- name: bootstrap community
run: |
cd client
python bootstrap_demo_community.py
python bootstrap_demo_community.py --test
test-community-growing:
runs-on: ubuntu-latest
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 108 additions & 10 deletions client/bootstrap_demo_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,29 @@
TEST_LOCATIONS_MEDITERRANEAN = 'test-locations-mediterranean.json'


def perform_meetup(client, cid):
def check_participant_count(client, cid, type, number):
participants_list = client.list_participants(cid)
print(participants_list)
expected_string = f"""Querying {type}Registry
number of participants assigned: {number}"""
if not expected_string in participants_list:
print(f"ERROR: Not {number} {type}s registered")
exit(1)

def check_reputation(client, cid, account, cindex, reputation):
rep = client.reputation(account)
print(rep)
if (str(cindex), f" {cid}", reputation) not in rep:
print(f"Reputation for {account} in cid {cid} cindex {cindex} is not {reputation}")
exit(1)


def perform_meetup(client, cid, accounts):
print('Starting meetup...')

print('Attest other attendees...')
client.attest_attendees(account1, cid, [account2, account3])
client.attest_attendees(account2, cid, [account1, account3])
client.attest_attendees(account3, cid, [account1, account2])
for account in accounts:
client.attest_attendees(account, cid, [a for a in accounts if a != account])


def update_spec_with_cid(file, cid):
Expand Down Expand Up @@ -85,18 +101,18 @@ def register_participants_and_perform_meetup(client, cid, accounts):
client.next_phase()

print(f'Performing meetups for cid {cid}')
perform_meetup(client, cid)
perform_meetup(client, cid, accounts)

print(f"Waiting for {blocks_to_wait} blocks, such that xt's are processed...")
client.await_block(blocks_to_wait)

print(client.list_attestees(cid))


def faucet(client, cid):
def faucet(client, cid, accounts):
# charlie has no genesis funds
print('Faucet is dripping to Charlie...')
client.faucet([account3], is_faucet=True)
print('Faucet is dripping...')
client.faucet(accounts, is_faucet=True)

blocks_to_wait = 3
print(f"Waiting for {blocks_to_wait} blocks, such that xt's are processed...")
Expand Down Expand Up @@ -168,31 +184,109 @@ def test_reputation_caching(client, cid, account):
print("reputation was not cleared")
exit(1)

client.next_phase()
client.next_phase()
client.await_block(1)
# registering


def test_unregister_and_upgrade_registration(client, cid):
newbie = client.create_accounts(1)[0]
faucet(client, cid, [newbie])

register_participants_and_perform_meetup(client, cid, accounts + [newbie])
client.next_phase()
client.await_block(1)

client.register_participant(newbie, cid)
client.await_block(1)
print(client.list_participants(cid))
check_participant_count(client, cid, "Newbie", 1)

claim_rewards(client, cid, account1, pay_fees_in_cc=True)
client.await_block(1)

check_reputation(client, cid, newbie, 6, "VerifiedUnlinked")
client.upgrade_registration(newbie, cid)
client.await_block(1)

check_participant_count(client, cid, "Newbie", 0)
check_participant_count(client, cid, "Reputable", 1)

check_reputation(client, cid, newbie, 6, "VerifiedLinked")

client.unregister_participant(newbie, cid, cindex=6)
client.await_block(3)
check_participant_count(client, cid, "Reputable", 0)

check_reputation(client, cid, newbie, 6, "VerifiedUnlinked")


def test_endorsements_by_reputables(client, cid):
newbies = client.create_accounts(7)
faucet(client, cid, newbies)

register_participants_and_perform_meetup(client, cid, accounts + newbies[:1])
client.next_phase()
client.await_block(1)
claim_rewards(client, cid, account1, pay_fees_in_cc=True)
client.await_block(1)
# newbies[0] is now reputable
check_participant_count(client, cid, "Endorsee", 0)

# endorsement works before registration
client.endorse_newcomers(cid, newbies[0], [newbies[1]])
client.await_block(1)
client.register_participant(newbies[1], cid)
client.await_block(1)
check_participant_count(client, cid, "Endorsee", 1)

# endorsement works after registration
for i in range(2, 6):
client.register_participant(newbies[i], cid)
client.await_block(1)
client.endorse_newcomers(cid, newbies[0], [newbies[i]])
client.await_block(1)

check_participant_count(client, cid, "Endorsee", i)

# all tickets used, should fail
print(client.endorse_newcomers(cid, newbies[0], [newbies[6]]))
client.await_block(2)
# endorsee count is still 5
check_participant_count(client, cid, "Endorsee", 5)

@click.command()
@click.option('--client', default='../target/release/encointer-client-notee', help='Client binary to communicate with the chain.')
@click.option('--port', default='9944', help='ws-port of the chain.')
@click.option('-l', '--ipfs-local', is_flag=True, help='if set, local ipfs node is used.')
@click.option('-s', '--spec-file', default=f'{TEST_DATA_DIR}{TEST_LOCATIONS_MEDITERRANEAN}', help='Specify community spec-file to be registered.')
def main(ipfs_local, client, port, spec_file):
@click.option('-t', '--test', is_flag=True, help='if set, run integration tests.')
def main(ipfs_local, client, port, spec_file, test):
client = Client(rust_client=client, port=port)
cid = create_community(client, spec_file, ipfs_local)

faucet(client, cid)
newbie = client.create_accounts(1)[0]
faucet(client, cid, [account3, newbie])

register_participants_and_perform_meetup(client, cid, accounts)

balance = client.balance(account1)

print("Claiming early rewards")
claim_rewards(client, cid, account1)

if(not balance == client.balance(account1)):
print("claim_reward fees were not refunded if paid in native currency")
exit(1)

client.next_phase()
client.await_block(1)

if(not test):
print(f"Community {cid} sucessfullly bootatrapped")
return(0)

print(f'Balances for new community with cid: {cid}.')
bal = [client.balance(a, cid=cid) for a in accounts]
[print(f'Account balance for {ab[0]} is {ab[1]}.') for ab in list(zip(accounts, bal))]
Expand Down Expand Up @@ -221,6 +315,10 @@ def main(ipfs_local, client, port, spec_file):

test_reputation_caching(client, cid, accounts)

test_unregister_and_upgrade_registration(client, cid)

test_endorsements_by_reputables(client, cid)

print("tests passed")


Expand Down
Loading

0 comments on commit bed1623

Please sign in to comment.