This repository was archived by the owner on Dec 9, 2019. It is now read-only.
forked from tbfleming/eos-altjs
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest.html
120 lines (111 loc) · 4.1 KB
/
test.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<pre style="width: 100%; height: 100%; margin:0px; "></pre>
<script src='dist-web/eosjs-debug.js'></script>
<script src='dist-web/eosjs-jsonrpc-debug.js'></script>
<script src='dist-web/eosjs-jssig-debug.js'></script>
<script>
let pre = document.getElementsByTagName('pre')[0];
const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; // useraaaaaaaa
const rpc = new eosjs_jsonrpc.JsonRpc('http://localhost:8000');
const signatureProvider = new eosjs_jssig.default([defaultPrivateKey]);
const api = new eosjs.Api({ rpc, signatureProvider });
function waitTwoSeconds() {
return new Promise(resolve => setTimeout(resolve, 2000));
}
(async () => {
try {
const resultWithConfig = await api.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
to: 'useraaaaaaab',
quantity: '0.0001 SYS',
memo: '',
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
pre.textContent += '\n\nTransaction with configured TAPOS pushed!\n\n' + JSON.stringify(resultWithConfig, null, 2);
await waitTwoSeconds(); // run additional tests after 2 second delay
const resultWithoutBroadcast = await api.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
to: 'useraaaaaaab',
quantity: '0.0001 SYS',
memo: '',
},
}]
}, {
broadcast: false,
blocksBehind: 3,
expireSeconds: 30,
});
pre.textContent = '\n\nTransaction serialized and signed but not pushed!\n\n' + JSON.stringify(resultWithoutBroadcast, null, 2);
await waitTwoSeconds();
const broadcastResult = await api.pushSignedTransaction(resultWithoutBroadcast);
pre.textContent = '\n\nSerialized Transaction and signatures pushed!\n\n' + JSON.stringify(broadcastResult, null, 2);
/* The test below will not work with hardcoded values for ref_block_num and prefix, we need to use the response from the previous test to retrieve those when full test suite is implemented
await waitTwoSeconds();
const currentDate = new Date();
const timePlusTen = currentDate.getTime() + 10000;
const timeInISOString = (new Date(timePlusTen)).toISOString();
const expiration = timeInISOString.substr(0, timeInISOString.length - 1);
const resultWithoutConfig = await api.transact({
expiration,
ref_block_num: 47657,
ref_block_prefix: 3285495572,
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
to: 'useraaaaaaab',
quantity: '0.0001 SYS',
memo: '',
},
}]
});
pre.textContent = '\n\nTransaction with manual TAPOS pushed!\n\n' + JSON.stringify(resultWithoutConfig, null, 2);
*/
await waitTwoSeconds();
const resultShouldFail = await api.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: {
from: 'useraaaaaaaa',
to: 'useraaaaaaab',
quantity: '0.0001 SYS',
memo: '',
},
}]
});
} catch (e) {
pre.textContent = '\nCaught exception: ' + e;
if (e instanceof eosjs_jsonrpc.RpcError)
pre.textContent += '\n\n' + JSON.stringify(e.json, null, 2);
}
})();
</script>