This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from EOSIO/beta3-prep
Beta3 prep
- Loading branch information
Showing
12 changed files
with
263 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import JsonRpc from "./eosjs-jsonrpc"; | ||
import RpcError from "./eosjs-rpcerror"; | ||
|
||
export { JsonRpc as default, RpcError }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<pre style='width: 100%; height: 100%; margin:0px; '></pre> | ||
|
||
<script src='../../dist-web/eosjs-api-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.default('http://localhost:8888'); | ||
const signatureProvider = new eosjs_jssig.default([defaultPrivateKey]); | ||
const api = new eosjs_api.default({ 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); | ||
await waitTwoSeconds(); | ||
|
||
const blockInfo = await rpc.get_block(broadcastResult.processed.block_num) | ||
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: blockInfo.block_num & 0xffff, | ||
ref_block_prefix: blockInfo.ref_block_prefix, | ||
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); | ||
} | ||
catch(e) { | ||
throw new Error('Web Integration Test Failed Unexpectedly: ' + e.message) | ||
} | ||
await waitTwoSeconds(); | ||
|
||
let failedAsPlanned; | ||
try { | ||
failedAsPlanned = true; | ||
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: '', | ||
}, | ||
}] | ||
}); | ||
failedAsPlanned = false; | ||
} catch (e) { | ||
if (e.message == 'Required configuration or TAPOS fields are not present') { | ||
pre.textContent = '\n\nCaught Exception successfully: \n\n' + e; | ||
} | ||
else { failedAsPlanned = false } | ||
} | ||
if (!failedAsPlanned) { | ||
throw new Error('The final transact call (lacking TAPoS and config) did not fail as expected'); | ||
} | ||
await waitTwoSeconds(); | ||
|
||
try { | ||
failedAsPlanned = true; | ||
const invalidRpcCall = await rpc.get_block(-1); | ||
failedAsPlanned = false; | ||
} | ||
catch(e) { | ||
if (e instanceof eosjs_jsonrpc.RpcError) { | ||
pre.textContent = '\n\nCaught RpcError successfully: \n\n' + JSON.stringify(e.json, null, 2); | ||
} | ||
else { | ||
failedAsPlanned = false; | ||
} | ||
} | ||
if (!failedAsPlanned) { | ||
throw new Error('An rpc error is not being thrown for invalid rpc calls'); | ||
} | ||
await waitTwoSeconds(); | ||
|
||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "CommonJS", | ||
"outDir": "dist", | ||
"alwaysStrict": true, | ||
"sourceMap": false, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"declaration": false, | ||
"downlevelIteration": true, | ||
"lib": [ | ||
"es2017", | ||
"dom" | ||
] | ||
}, | ||
"include": [ | ||
"src/*.ts", | ||
"src/*.js" | ||
], | ||
"exclude": [ | ||
"src/*.test.ts" | ||
] | ||
} |
Oops, something went wrong.