-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
80 lines (67 loc) · 2.11 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import sys
import json
import struct
import pytest
test_dir = os.path.dirname(__file__)
sys.path.append(os.path.join(test_dir, '..'))
from ipyeos import log
from ipyeos import chaintester
from ipyeos.chaintester import ChainTester
chaintester.chain_config['contracts_console'] = True
logger = log.get_logger(__name__)
def update_auth(tester, account):
a = {
"account": account,
"permission": "active",
"parent": "owner",
"auth": {
"threshold": 1,
"keys": [
{
"key": 'EOS6AjF6hvF7GSuSd4sCgfPKq5uWaXvGM2aQtEUCwmEHygQaqxBSV',
"weight": 1
}
],
"accounts": [{"permission":{"actor":account,"permission": 'eosio.code'}, "weight":1}],
"waits": []
}
}
tester.push_action('eosio', 'updateauth', a, {account:'active'})
def init_tester():
tester = chaintester.ChainTester()
update_auth(tester, 'hello')
return tester
def chain_test(fn):
def call():
tester = init_tester()
ret = fn(tester)
tester.free()
return ret
return call
class NewChainTester():
def __init__(self):
self.tester = None
def __enter__(self):
self.tester = init_tester()
return self.tester
def __exit__(self, type, value, traceback):
self.tester.free()
test_dir = os.path.dirname(__file__)
def deploy_contract(tester, package_name):
with open(f'{test_dir}/assembly/target/{package_name}.wasm', 'rb') as f:
code = f.read()
with open(f'{test_dir}/assembly/target/{package_name}.abi', 'rb') as f:
abi = f.read()
tester.deploy_contract('hello', code, abi)
@chain_test
def test_hello(tester):
deploy_contract(tester, 'counter')
args = {}
r = tester.push_action('hello', 'inc', args, {'hello': 'active'})
logger.info('++++++elapsed: %s', r['elapsed'])
tester.produce_block()
r = tester.push_action('hello', 'inc', args, {'hello': 'active'})
logger.info('++++++elapsed: %s', r['elapsed'])
tester.produce_block()
logger.info("+++++++test done!")