Skip to content

Commit

Permalink
add py test script for treasury and fees
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Sep 18, 2021
1 parent 6a0d4c3 commit 72e3f73
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions scripts/treasury-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 16 20:41:13 2021
@author: brenzi
"""

from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.utils.ss58 import ss58_encode

def get_balance(who):
return substrate.query('System', 'Account', params=[who]).value['data']['free']

substrate = SubstrateInterface(
url="ws://127.0.0.1:9944",
type_registry_preset='kusama'
)
alice = Keypair.create_from_uri('//Alice')
dave = Keypair.create_from_uri('//Dave')
treasury = ss58_encode('0x' + b'modlpy/trsry'.hex() + '0000000000000000000000000000000000000000')

alicebefore = get_balance(alice.ss58_address)
treasurybefore = get_balance(treasury)
totalissuancebefore = substrate.query('Balances', 'TotalIssuance')
print('total issuance', totalissuancebefore)

amount = 10 * 10**9 #milli

call = substrate.compose_call(
call_module='Balances',
call_function='transfer',
call_params={
'dest': dave.ss58_address,
'value': amount
}
)

payment_info = substrate.get_payment_info(call=call, keypair=alice)
print("Payment info: ", payment_info)

extrinsic = substrate.create_signed_extrinsic(
call=call,
keypair=alice,
era={'period': 64}
)
receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
print('extrinsic sent')

totalissuanceafter = substrate.query('Balances', 'TotalIssuance')
print('difference in total issuance: ', totalissuancebefore.value - totalissuanceafter.value)

aliceafter = get_balance(alice.ss58_address)

paidfee = alicebefore - aliceafter - amount
print('fee paid : ', paidfee)

treasuryafter = get_balance(treasury)

print('treasury balance is ', treasuryafter, ' and has increased by', treasuryafter-treasurybefore)

0 comments on commit 72e3f73

Please sign in to comment.