-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test task for ligo plugin (#1255)
* Add test task for ligo plugin * Fix help menu tests * Clean up unused imports * Add doc for test task of ligo plugin * Added e2e tests * Added e2e tests Co-authored-by: Ivan Romanov <sinapsist@gmail.com>
- Loading branch information
Showing
12 changed files
with
333 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { execCmd, getArch, sendAsyncErr, sendErr, sendJsonRes, sendWarn } from '@taqueria/node-sdk'; | ||
import { RequestArgs } from '@taqueria/node-sdk/types'; | ||
import { join } from 'path'; | ||
|
||
interface Opts extends RequestArgs.t { | ||
sourceFile: string; | ||
} | ||
|
||
type TableRow = { contract: string; testResults: string }; | ||
|
||
const getInputFilename = (parsedArgs: Opts, sourceFile: string): string => | ||
join(parsedArgs.config.contractsDir, sourceFile); | ||
|
||
const getTestContractCmd = (parsedArgs: Opts, sourceFile: string): string => { | ||
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir; | ||
if (!projectDir) throw `No project directory provided`; | ||
const baseCmd = | ||
`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ligolang/ligo:next run test`; | ||
const inputFile = getInputFilename(parsedArgs, sourceFile); | ||
const cmd = `${baseCmd} ${inputFile}`; | ||
return cmd; | ||
}; | ||
|
||
const testContract = (parsedArgs: Opts, sourceFile: string): Promise<TableRow> => | ||
getArch() | ||
.then(() => getTestContractCmd(parsedArgs, sourceFile)) | ||
.then(execCmd) | ||
.then(({ stdout, stderr }) => { | ||
if (stderr.length > 0) sendWarn(stderr); | ||
const result = '🎉 All tests passed 🎉'; | ||
return { | ||
contract: sourceFile, | ||
testResults: stdout.length > 0 ? `${stdout}\n${result}` : result, | ||
}; | ||
}) | ||
.catch(err => { | ||
sendErr(`\n=== For ${sourceFile} ===`); | ||
sendErr(err.message.replace(/Command failed.+?\n/, '')); | ||
return { | ||
contract: sourceFile, | ||
testResults: 'Some tests failed :(', | ||
}; | ||
}); | ||
|
||
export const test = (parsedArgs: Opts): Promise<void> => { | ||
const sourceFile = parsedArgs.sourceFile; | ||
return testContract(parsedArgs, sourceFile).then(result => [result]).then(sendJsonRes).catch(err => | ||
sendAsyncErr(err, false) | ||
); | ||
}; | ||
|
||
export default test; |
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 @@ | ||
#include "hello-tacos.mligo" | ||
|
||
let available_tacos = 100 | ||
|
||
let test_available_tacos = | ||
let (taddr, _, _) = Test.originate main initial_storage 100tez in | ||
assert (Test.get_storage taddr = available_tacos) | ||
|
||
let test_buy_tacos = | ||
let (taddr, _, _) = Test.originate main initial_storage 100tez in | ||
let contr = Test.to_contract taddr in | ||
let _ = Test.transfer_to_contract_exn contr 1mutez in | ||
assert (Test.get_storage taddr = test_available_tacos - 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "hello-tacos.mligo" | ||
|
||
let available_tacos = 100n | ||
|
||
let test_available_tacos = | ||
let (taddr, _, _) = Test.originate main available_tacos 100tez in | ||
assert (Test.get_storage taddr = available_tacos) | ||
|
||
let test_buy_tacos = | ||
let res = main(1n, available_tacos) in (* The nature of the contract we don't have entrypoints | ||
// The only way to test it is to call function itself *) | ||
assert (res.1 = 99n) |
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
Oops, something went wrong.