-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the execution module & fix events
Add a unit test for the event generation, build a local wasm project on massa-execution build. Then execute the test. Fixes: the events where not stored correctly in `final_events` Changes: Flter slot, include last slot.
- Loading branch information
1 parent
2156f2b
commit 1c09292
Showing
15 changed files
with
291 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
// Build also the wasm files massa-execution if test | ||
let _ = std::process::Command::new("yarn") | ||
.current_dir("./src/tests/wasm_tests") | ||
.args(&["install"]) | ||
.status(); | ||
let _ = std::process::Command::new("yarn") | ||
.current_dir("./src/tests/wasm_tests") | ||
.args(&["build"]) | ||
.status(); | ||
} |
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,3 @@ | ||
build/ | ||
node_modules | ||
ledger.json |
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,20 @@ | ||
{ | ||
"targets": { | ||
"debug": { | ||
"binaryFile": "build/untouched.wasm", | ||
"textFile": "build/untouched.wat", | ||
"sourceMap": true, | ||
"debug": true | ||
}, | ||
"release": { | ||
"binaryFile": "build/optimized.wasm", | ||
"textFile": "build/optimized.wat", | ||
"sourceMap": true, | ||
"optimizeLevel": 3, | ||
"shrinkLevel": 0, | ||
"converge": false, | ||
"noAssert": false | ||
} | ||
}, | ||
"options": {} | ||
} |
12 changes: 12 additions & 0 deletions
12
massa-execution/src/tests/wasm_tests/bin/include_base64.js
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,12 @@ | ||
const fs = require('fs'); | ||
const file = process.argv[2]; | ||
const match = require('./match_include_base64'); | ||
const lines = String(fs.readFileSync(file)).split('\n').map(line => { | ||
let res = match(line); | ||
if (res != null) { | ||
const data = fs.readFileSync(res[1], 'base64'); | ||
line = line.replace(res[0], JSON.stringify(data)); | ||
} | ||
return line; | ||
}); | ||
fs.writeFileSync(file.replace('.ts', '.m.ts'), lines.join('\n'), { flag: 'w+' }); |
2 changes: 2 additions & 0 deletions
2
massa-execution/src/tests/wasm_tests/bin/match_include_base64.js
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,2 @@ | ||
const include_bytes_regex = /include_base64\(["']+([\.a-z_\-\/\\ ]*)["']+\)[;]+/i; | ||
module.exports = (line) => line.match(include_bytes_regex); |
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,13 @@ | ||
{ | ||
"name": "wasm_tests", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"build": "asc src/event_test.ts --target release --exportRuntime --binaryFile build/event_test.wasm" | ||
}, | ||
"dependencies": { | ||
"assemblyscript": "^0.19.20", | ||
"json-as": "^0.2.6", | ||
"massa-sc-std": "2.0.0", | ||
"visitor-as": "^0.6.0" | ||
} | ||
} |
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,14 @@ | ||
/** *************************************************************************** | ||
* This file show you an example of how to call a smart contract | ||
* | ||
* Once you ran the command `yarn run-sc | ||
**/ | ||
|
||
import { generate_event, print } from "massa-sc-std"; | ||
|
||
export function main(_args: string): string { | ||
print("hehehe") | ||
|
||
generate_event("hello world") | ||
return "0" | ||
} |
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,6 @@ | ||
{ | ||
"extends": "assemblyscript/std/assembly.json", | ||
"include": [ | ||
"./**/*.ts" | ||
] | ||
} |
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,75 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
as-string-sink@^0.4.2: | ||
version "0.4.2" | ||
resolved "https://registry.yarnpkg.com/as-string-sink/-/as-string-sink-0.4.2.tgz#e3d51fe8c3810d61b6ff2b5259fdd168b56d6bd9" | ||
integrity sha512-eOuOYPUwwv4QumoJIa7XxyS0OjXI6CyZz2dtba/hTeG5hzhq58HzAPD2FbHhjfYUXQaSAacFnJ9g2Zlfw56LgQ== | ||
|
||
assemblyscript@^0.19.20: | ||
version "0.19.22" | ||
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.22.tgz#ef7eb8939864bd1b7603a9772e8f32e1fcfb8975" | ||
integrity sha512-+Rclbx0+BI3qAe9fjc8XGbSUDaayTtjINnD19I4MmfpT2R43c9YTQERP36676shkPxb1fisDFZeSTL65Da8Q2g== | ||
dependencies: | ||
binaryen "102.0.0-nightly.20211028" | ||
long "^5.2.0" | ||
source-map-support "^0.5.20" | ||
|
||
binaryen@102.0.0-nightly.20211028: | ||
version "102.0.0-nightly.20211028" | ||
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-102.0.0-nightly.20211028.tgz#8f1efb0920afd34509e342e37f84313ec936afb2" | ||
integrity sha512-GCJBVB5exbxzzvyt8MGDv/MeUjs6gkXDvf4xOIItRBptYl0Tz5sm1o/uG95YK0L0VeG5ajDu3hRtkBP2kzqC5w== | ||
|
||
buffer-from@^1.0.0: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" | ||
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== | ||
|
||
json-as@^0.2.6: | ||
version "0.2.6" | ||
resolved "https://registry.yarnpkg.com/json-as/-/json-as-0.2.6.tgz#4598b1b038a99fac2ebce3cfb0d126b7b346de29" | ||
integrity sha512-adGnfJB57eQwVnw0yP3b0yUBhRWa9QUr/JDAgjYV2yvbl5ckV9P3ARAGwXywiZhOE854k1zL29vB7uGRZhM0cQ== | ||
dependencies: | ||
as-string-sink "^0.4.2" | ||
|
||
lodash.clonedeep@^4.5.0: | ||
version "4.5.0" | ||
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef" | ||
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= | ||
|
||
long@^5.2.0: | ||
version "5.2.0" | ||
resolved "https://registry.yarnpkg.com/long/-/long-5.2.0.tgz#2696dadf4b4da2ce3f6f6b89186085d94d52fd61" | ||
integrity sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w== | ||
|
||
massa-sc-std@2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/massa-sc-std/-/massa-sc-std-2.0.0.tgz#7c75e3c04295deae4f80383c1d73c0ac45bf58f9" | ||
integrity sha512-gpMX4iGWAzI6PTpb/wGYH3RN+q585o3ixFuaHnD7VuL2amqFlFW44RwZESPPVBcq+nBWypJxz2pt6hxOA/gjLQ== | ||
|
||
source-map-support@^0.5.20: | ||
version "0.5.21" | ||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" | ||
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== | ||
dependencies: | ||
buffer-from "^1.0.0" | ||
source-map "^0.6.0" | ||
|
||
source-map@^0.6.0: | ||
version "0.6.1" | ||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" | ||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== | ||
|
||
ts-mixer@^5.4.1: | ||
version "5.4.1" | ||
resolved "https://registry.yarnpkg.com/ts-mixer/-/ts-mixer-5.4.1.tgz#b90db9ced48531aa17ce9184a2890d1e3c99b1e5" | ||
integrity sha512-Zo9HgPCtNouDgJ+LGtrzVOjSg8+7WGQktIKLwAfaNrlOK1mWGlz1ejsAF/YqUEqAGjUTeB5fEg8gH9Aui6w9xA== | ||
|
||
visitor-as@^0.6.0: | ||
version "0.6.0" | ||
resolved "https://registry.yarnpkg.com/visitor-as/-/visitor-as-0.6.0.tgz#b0cca3c918bd9d396545faf08529d2b9ba968a40" | ||
integrity sha512-4WcnwCLXWjhNkwJj9gSqh46sdIv9CyIvnSuwr61OOfrGCtN2mKcW5KE828OeEr1rYjEy0Z/CIdPBJKJRLsUgDA== | ||
dependencies: | ||
lodash.clonedeep "^4.5.0" | ||
ts-mixer "^5.4.1" |
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