-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiline Arguments and Optionals (#17)
* Update code * Update flow.json * Start api documentation * Add example tests * Remove spaces in getArrayType result * Add method to completely remove all spaces in a string * Export additional methods and arguments * Add more tests and API documentation * Replace default dependency * Update templates * Add fix for non existent folders * Add test Cadence templates for generator * Add generator tests * Regenerate templates * Add documentation for Prettier and generator related methods * Reformat headers. refactor method description * Update environment logic. add setEnvironment method * Add env tests * Export additional methods * Add docs for environment methods * Ad aliases * Add transaction documentation * Fix dev tests * Refactor for seal status * Update handlebars templates to default interaction props to empty object * update package lock * Refactor parser to work with multiline arguments * Add Optionals mapping * Move generator tests into new folder * Create tests for Optionals * fix test name * Refactor code for mapped arguments * Update generate-dev test * Fix emulator logging. Add Dictionary test * Refactor Dictionary resolver * Fix failing tests * Add ignore pattern for dev tests * Fix code for failed tests. Update tests * Update import * Add tests for multiline arguments. Update parser to remove trailing comma * Update changelog * Update CHANGELOG * Add crypto libraries for signing transactions * Add tx related utilities * Add transactions tests * Update private key * Bump version. Move prettier into dependencies * Refactor
- Loading branch information
Maksim Daunarovich
authored
Sep 20, 2021
1 parent
340e73d
commit 9c050e8
Showing
44 changed files
with
22,362 additions
and
485 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,12 @@ | ||
module.exports = { | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current" | ||
} | ||
} | ||
] | ||
] | ||
} |
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 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
verbose: true, | ||
coveragePathIgnorePatterns: ["/node_modules/"], | ||
}; |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
import path from "path"; | ||
import { emulator, init } from "flow-js-testing"; | ||
import { query } from "@onflow/fcl"; | ||
import { mapValuesToCode } from "../../src"; | ||
import { padAddress, toFixedValue } from "../../src/fixer"; | ||
|
||
// Increase timeout if your tests failing due to timeout | ||
jest.setTimeout(10000); | ||
|
||
describe("optional arguments", () => { | ||
beforeEach(async () => { | ||
const basePath = path.resolve(__dirname, "../cadence"); | ||
// You can specify different port to parallelize execution of describe blocks | ||
const port = 8080; | ||
// Setting logging flag to true will pipe emulator output to console | ||
const logging = false; | ||
|
||
await init(basePath, { port }); | ||
return emulator.start(port, logging); | ||
}); | ||
|
||
// Stop emulator, so it could be restarted | ||
afterEach(async () => { | ||
return emulator.stop(); | ||
}); | ||
|
||
it("optionals - String? - no value", async () => { | ||
const input = null; | ||
const cadence = ` | ||
pub fun main(message: String?): String?{ | ||
return message | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(input); | ||
}); | ||
it("optionals - String? - with value", async () => { | ||
const input = "Cadence"; | ||
const cadence = ` | ||
pub fun main(message: String?): String?{ | ||
return message | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(input); | ||
}); | ||
it("optionals - Address? - no value", async () => { | ||
const input = null; | ||
const expected = false; | ||
const cadence = ` | ||
pub fun main(address: Address?): Bool{ | ||
if(address != nil){ | ||
return true | ||
} | ||
return false | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("optionals - Address? - with value", async () => { | ||
const input = "0x01"; | ||
const expected = true; | ||
const cadence = ` | ||
pub fun main(address: Address?): Bool{ | ||
if(address != nil){ | ||
return true | ||
} | ||
return false | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("optionals - [String?] - no value", async () => { | ||
const input = [null]; | ||
const expected = null; | ||
const cadence = ` | ||
pub fun main(names: [String?]): String?{ | ||
return names[0] | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("optionals - [String?] - with value", async () => { | ||
const input = ["Cadence"]; | ||
const expected = "Cadence"; | ||
const cadence = ` | ||
pub fun main(names: [String?]): String?{ | ||
return names[0] | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("optionals - {String: String?} - no value", async () => { | ||
const input = { name: "Cadence" }; | ||
const expected = null; | ||
const cadence = ` | ||
pub fun main(metadata: {String: String?}): String?{ | ||
log(metadata) | ||
let meta = metadata["empty"] | ||
if ( meta == nil){ | ||
return nil | ||
} | ||
return meta! | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("optionals - {String: String?} - with value", async () => { | ||
const input = { name: "Cadence" }; | ||
const expected = "Cadence"; | ||
const cadence = ` | ||
pub fun main(metadata: {String: String?}): String?{ | ||
return metadata["name"]! | ||
} | ||
`; | ||
|
||
const args = () => mapValuesToCode(cadence, [input]); | ||
const output = await query({ cadence, args }); | ||
|
||
expect(output).toBe(expected); | ||
}); | ||
it("case suit", async () => { | ||
const makeTemplate = (type) => ` | ||
pub fun main(message: ${type}?): ${type}?{ | ||
return message | ||
} | ||
`; | ||
|
||
const StringMap = ` | ||
pub fun main(metadata: {String: String?}, key: String): String?{ | ||
return metadata[key]! | ||
} | ||
`; | ||
|
||
const StringArray = ` | ||
pub fun main(names: [String?]): String?{ | ||
return names[0] | ||
} | ||
`; | ||
|
||
const templates = { | ||
UFix64: makeTemplate("UFix64"), | ||
String: makeTemplate("String"), | ||
Address: makeTemplate("Address"), | ||
}; | ||
|
||
const tests = [ | ||
{ | ||
input: "Cadence", | ||
cadence: templates.String, | ||
}, | ||
{ | ||
input: null, | ||
cadence: templates.String, | ||
}, | ||
{ | ||
input: toFixedValue(1.337), | ||
cadence: templates.UFix64, | ||
}, | ||
{ | ||
input: null, | ||
cadence: templates.UFix64, | ||
}, | ||
{ | ||
input: padAddress("0x01"), | ||
cadence: templates.Address, | ||
}, | ||
{ | ||
input: null, | ||
cadence: templates.Address, | ||
}, | ||
{ | ||
input: ["Cadence"], | ||
cadence: StringArray, | ||
expected: "Cadence", | ||
}, | ||
{ | ||
input: [null], | ||
cadence: StringArray, | ||
expected: null, | ||
}, | ||
{ | ||
rawArgs: [ | ||
{ | ||
name: "James", | ||
}, | ||
"name", | ||
], | ||
cadence: StringMap, | ||
expected: "James", | ||
}, | ||
]; | ||
|
||
for (const i in tests) { | ||
const { input, expected, cadence, rawArgs } = tests[i]; | ||
|
||
const mapped = mapValuesToCode(cadence, rawArgs || [input]); | ||
const args = () => mapped; | ||
const output = await query({ cadence, args }); | ||
await expect(output).toBe(expected === undefined ? input : expected); | ||
} | ||
await expect.assertions(tests.length); | ||
}); | ||
}); |
Oops, something went wrong.