-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathfixed_supply_token_test.py
executable file
·46 lines (36 loc) · 1.99 KB
/
fixed_supply_token_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import time
from conflux.utils import priv_to_addr
from test_framework.smart_contract_bench_base import SmartContractBenchBase
from web3 import Web3
import os
from test_framework.util import load_contract_metadata
class FixedTokenSupplyTokenTest(SmartContractBenchBase):
def __init__(self):
super().__init__()
self.contract_address = ""
self.contract = None
self.accounts = []
def setup_contract(self):
metadata = load_contract_metadata("ERC20")
self.contract = Web3().eth.contract(
abi=metadata["abi"],
bytecode=metadata["bytecode"],
)
self.log.info("Initializing contract")
transaction = self.call_contract_function(self.contract, "constructor", [], self.default_account_key, storage_limit=20000)
self.contract_address = self.wait_for_tx([transaction], True)[0]['contractCreated']
self.accounts = [a[0] for a in self.new_address_and_transfer(2)]
def generate_transactions(self, _):
self.call_contract_function(self.contract, "transfer",
[Web3.to_checksum_address(priv_to_addr(self.accounts[0])), 1000],
self.default_account_key, self.contract_address, True, True, storage_limit=512)
self.call_contract_function(self.contract, "approve",
[Web3.to_checksum_address(priv_to_addr(self.accounts[1])), 500],
self.accounts[0], self.contract_address, True, True, storage_limit=512)
self.call_contract_function(self.contract, "transferFrom",
[Web3.to_checksum_address(priv_to_addr(self.accounts[0])),
Web3.to_checksum_address(priv_to_addr(self.default_account_key)), 300],
self.accounts[1], self.contract_address, True, True, storage_limit=512)
if __name__ == "__main__":
FixedTokenSupplyTokenTest().main()