-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: constructor validation on build (#226)
* fix: constructor validation on build * Update unordered-map.js * feat: constructor checker * feat: constructor validation * fix: resolve conflicts * fix: resolve conflicts * fix: code cleaning * fix: code cleaning * fix: code cleaning * fix: lint * fix: tests * fix: empty state contract * fix: update contract valdiation to handle clean-state example * linter fix * constructor validation moved to utils * constructor test contracts renamed, typos fixed * redandunt comment deleted * Error messages changed * log comments added to contract validation * yarn build * cli/cli.js deleted * contract validation added to the main pipeline * contract validation rewrittent with TS * signal used in contract validation, tests rewritten * contract validation doc added Co-authored-by: Serhii Volovyk <SergeyVolovyk@gmail.com>
- Loading branch information
1 parent
ef1a7b2
commit 04a0b6d
Showing
16 changed files
with
2,099 additions
and
1,101 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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 @@ | ||
import test from "ava"; | ||
import { execSync } from "child_process"; | ||
|
||
const BUILD_FAILURE_ERROR_CODE = 1; | ||
|
||
test("should not throw error, constructor is correctly initialized", async (t) => { | ||
t.notThrows(() => { | ||
execSync( | ||
"near-sdk-js build src/constructor-validation/all-parameters-set-in-constructor.ts build/all-parameters-set-in-constructor.wasm" | ||
); | ||
}); | ||
}); | ||
|
||
test("should throw error, name is not inited", async (t) => { | ||
const error = t.throws(() => { | ||
execSync( | ||
"near-sdk-js build src/constructor-validation/1-parameter-not-set-in-constructor.ts build/1-parameter-not-set-in-constructor.wasm" | ||
); | ||
}); | ||
t.is(error.status, BUILD_FAILURE_ERROR_CODE); | ||
}); | ||
|
||
test("should throw error, construcor is empty", async (t) => { | ||
const error = t.throws(() => { | ||
execSync( | ||
"near-sdk-js build src/constructor-validation/no-parameters-set-in-constructor.ts build/no-parameters-set-in-constructor.wasm" | ||
); | ||
}); | ||
t.is(error.status, BUILD_FAILURE_ERROR_CODE); | ||
}); | ||
|
||
test("should throw error, construcor is not declared", async (t) => { | ||
const error = t.throws(() => { | ||
execSync( | ||
"near-sdk-js build src/constructor-validation/no-constructor.ts build/no-constructor.wasm" | ||
); | ||
}); | ||
t.is(error.status, BUILD_FAILURE_ERROR_CODE); | ||
}); |
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
10 changes: 10 additions & 0 deletions
10
tests/src/constructor-validation/1-parameter-not-set-in-constructor.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,10 @@ | ||
import { NearBindgen, LookupMap } from "near-sdk-js"; | ||
|
||
@NearBindgen({}) | ||
export class ConstructorValidation { | ||
map: LookupMap<string>; | ||
name: string; | ||
constructor() { | ||
this.map = new LookupMap<string>("a"); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/src/constructor-validation/all-parameters-set-in-constructor.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,16 @@ | ||
import { NearBindgen, LookupMap, call } from "near-sdk-js"; | ||
|
||
@NearBindgen({}) | ||
export class ConstructorValidation { | ||
map: LookupMap<string>; | ||
name: string; | ||
constructor() { | ||
this.map = new LookupMap<string>("a"); | ||
this.name = ""; | ||
} | ||
|
||
@call({}) | ||
get() { | ||
return { status: "ok" }; | ||
} | ||
} |
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,7 @@ | ||
import { NearBindgen, LookupMap } from "near-sdk-js"; | ||
|
||
@NearBindgen({}) | ||
export class ConstructorValidation { | ||
map: LookupMap<string>; | ||
name: string; | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/src/constructor-validation/no-parameters-set-in-constructor.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,10 @@ | ||
import { NearBindgen, LookupMap } from "near-sdk-js"; | ||
|
||
@NearBindgen({}) | ||
export class ConstructorValidation { | ||
map: LookupMap<string>; | ||
name: string; | ||
constructor() { | ||
// | ||
} | ||
} |
Oops, something went wrong.