-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
252 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { bytes } from 'multiformats'; | ||
import { BUILDER_NAMES, evaluate, init } from './index.mjs'; | ||
import type { EvalResult } from './proto_ts/eval_result.js'; | ||
|
||
const defaultCuLimit = 1000000n; | ||
|
||
export const evalFunction = async (codeStr: string): Promise<EvalResult> => { | ||
await init(); | ||
const codeString = [ | ||
` | ||
const evalFn = ${codeStr}`, | ||
` | ||
evalFn() | ||
`, | ||
]; | ||
return evaluate({ | ||
codeString, | ||
cuLimit: defaultCuLimit, | ||
storage: bytes.fromString(''), | ||
}); | ||
}; | ||
|
||
export const evalClass = async ( | ||
codeStr: string, | ||
method: string, | ||
params: string[] = [], | ||
): Promise<EvalResult> => { | ||
await init(); | ||
const codeString = [ | ||
` | ||
${codeStr} | ||
`, | ||
` | ||
const __run__class__ = new ${BUILDER_NAMES.CONTRACT_CLASS_NAME}(); | ||
__run__class__.${BUILDER_NAMES.CONSTRUCTOR_METHOD}(); | ||
__run__class__.${method}(${params?.join(',')}); | ||
`, | ||
]; | ||
return evaluate({ | ||
codeString, | ||
cuLimit: defaultCuLimit, | ||
storage: bytes.fromString(''), | ||
}); | ||
}; | ||
|
||
export const evalCode = async (code: string): Promise<EvalResult> => { | ||
await init(); | ||
return evaluate({ | ||
codeString: [code], | ||
cuLimit: defaultCuLimit, | ||
storage: bytes.fromString(''), | ||
}); | ||
}; |
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 was deleted.
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { bytes } from 'multiformats'; | ||
import { evalClass } from 'skchain'; | ||
|
||
export const runBuildContractTest = async (): Promise<boolean> => { | ||
const codeByte = (await import('./test.contract.js')) as unknown as { | ||
default: Uint8Array; | ||
}; | ||
const codeString = bytes.toString(codeByte.default); | ||
|
||
console.log(codeString); | ||
evalClass(codeString, 'getValue'); | ||
// TODO: eval code to test | ||
return true; | ||
}; |
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,5 @@ | ||
.monaco-editor { | ||
width: 50vw; | ||
height: 50vh; | ||
border: 1px solid #ccc; | ||
} |
Oops, something went wrong.