Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Fix passing numbers as values deprecation notice #188

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-penguins-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/flow-js-testing": patch
---

Fix numbers as values deprecation warnings for tests
4 changes: 2 additions & 2 deletions dev-test/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("interactions - sendTransaction", () => {

test("deploy custom contract with arguments", async () => {
const message = "Hello, Cadence"
const number = 42
const number = "42"
await shallPass(
deployContract({
code: `
Expand Down Expand Up @@ -128,7 +128,7 @@ describe("interactions - sendTransaction", () => {
`,
})
)
expect(numberResult).toBe(String(number))
expect(numberResult).toBe(number)
expect(numberErr).toBe(null)
})
})
6 changes: 3 additions & 3 deletions dev-test/interaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe("interactions - sendTransaction", () => {
}
}
`
const args = [42]
const args = ["42"]
return sendTransaction({code, args})
})
})
Expand All @@ -233,7 +233,7 @@ describe("interactions - sendTransaction", () => {
}
}
`
const args = [42, 1337, "Hello, Cadence"]
const args = ["42", "1337", "Hello, Cadence"]
return sendTransaction({code, args})
})
})
Expand All @@ -247,7 +247,7 @@ describe("interactions - sendTransaction", () => {
}
}
`
const args = [42, 1337, "Hello, Cadence"]
const args = ["42", "1337", "Hello, Cadence"]
return sendTransaction({code, args})
})
})
Expand Down
10 changes: 5 additions & 5 deletions dev-test/metadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ describe("metadata examples", () => {
return metadata["answer"]!
}
`
const answer = 42
const answer = "42"
const args = [{answer}]
const [result] = await shallResolve(executeScript({code, args}))
expect(result).toBe(String(answer))
expect(result).toBe(answer)
})

test("simple array - [String]", async () => {
Expand All @@ -60,12 +60,12 @@ describe("metadata examples", () => {
return list[0][index]
}
`
const value = [1, 3, 3, 7]
const index = 3
const value = ["1", "3", "3", "7"]
const index = "3"
const args = [[value], index]

const [result, err] = await executeScript({code, args})
expect(result).toBe(String(value[index]))
expect(result).toBe(value[index])
expect(err).toBe(null)
})
})
2 changes: 1 addition & 1 deletion dev-test/usage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("jest methods", () => {
`,
})
)
expect(result).toBe(String(42))
expect(result).toBe("42")
expect(err).toBe(null)
})

Expand Down
38 changes: 20 additions & 18 deletions dev-test/utilities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ describe("block height offset", () => {
const [zeroOffset] = await executeScript("get-block-offset")
expect(zeroOffset).toBe("0")

const offset = 42
const offset = "42"
await shallPass(sendTransaction("set-block-offset", [manager], [offset]))

const [newOffset] = await executeScript("get-block-offset")
expect(newOffset).toBe(String(offset))
expect(newOffset).toBe(offset)
})

it("should read offset with utility method", async () => {
Expand All @@ -66,11 +66,11 @@ describe("block height offset", () => {
const [oldOffset] = await getBlockOffset()
expect(oldOffset).toBe("0")

const offset = 42
const offset = "42"
await shallPass(setBlockOffset(offset))

const [newOffset] = await getBlockOffset()
expect(newOffset).toBe(String(offset))
expect(newOffset).toBe(offset)
})

it("should update offset in contract", async () => {
Expand All @@ -88,7 +88,7 @@ describe("block height offset", () => {
})
)

const offset = 42
const offset = "42"
await shallPass(manager.setBlockOffset(offset))

const realBlock = await query({
Expand All @@ -111,7 +111,7 @@ describe("block height offset", () => {
)

// Expect 1 higher than initial block height + offset due to sealed TX @ manager.setBlockOffset
expect(Number(currentBlock)).toBe(Number(realBlock) + offset)
expect(Number(currentBlock)).toBe(Number(realBlock) + Number(offset))
})
})

Expand All @@ -137,11 +137,11 @@ describe("block height offset utilities", () => {
const [offset] = await shallResolve(manager.getBlockOffset())
expect(offset).toBe("0")

const blockOffset = 42
const blockOffset = "42"
await shallPass(manager.setBlockOffset(blockOffset))

const [newOffset] = await shallResolve(manager.getBlockOffset())
expect(newOffset).toBe(String(blockOffset))
expect(newOffset).toBe(blockOffset)
})
})

Expand All @@ -168,12 +168,12 @@ describe("timestamp offset", () => {
const [zeroOffset] = await executeScript("get-timestamp-offset")
expect(zeroOffset).toBe("0.00000000")

const offset = 42
const offset = "42"
await shallPass(
sendTransaction("set-timestamp-offset", [manager], [offset])
)
const [newOffset] = await executeScript("get-timestamp-offset")
expect(newOffset).toBe(offset.toFixed(8))
expect(newOffset).toBe(Number(offset).toFixed(8))
})

it("should read offset with utility method", async () => {
Expand All @@ -185,11 +185,11 @@ describe("timestamp offset", () => {
const [oldOffset] = await getTimestampOffset()
expect(oldOffset).toBe("0.00000000")

const offset = 42
const offset = "42"
await shallPass(setTimestampOffset(offset))

const [newOffset] = await getTimestampOffset()
expect(newOffset).toBe(offset.toFixed(8))
expect(newOffset).toBe(Number(offset).toFixed(8))
})

it("should update offset in contract", async () => {
Expand All @@ -207,7 +207,7 @@ describe("timestamp offset", () => {
})
)

const offset = 42
const offset = "42"
await shallPass(manager.setTimestampOffset(offset))

const realTimestamp = await query({
Expand All @@ -229,7 +229,9 @@ describe("timestamp offset", () => {
})
)

expect(Number(currentTimestamp)).toBe(Number(realTimestamp) + offset)
expect(Number(currentTimestamp)).toBe(
Number(realTimestamp) + Number(offset)
)
})
})

Expand All @@ -255,11 +257,11 @@ describe("timestamp offset utilities", () => {
const [offset] = await shallResolve(manager.getTimestampOffset())
expect(offset).toBe("0.00000000")

const blockOffset = 42
const blockOffset = "42"
await shallPass(manager.setTimestampOffset(blockOffset))

const [newOffset] = await shallResolve(manager.getTimestampOffset())
expect(newOffset).toBe(blockOffset.toFixed(8))
expect(newOffset).toBe(Number(blockOffset).toFixed(8))
})
})

Expand All @@ -282,11 +284,11 @@ describe("dev tests", () => {
})

it("should return proper offset, when changed", async () => {
const offset = 42
const offset = "42"
const manager = await getServiceAddress()
await shallPass(sendTransaction("set-block-offset", [manager], [offset]))
const [newOffset] = await executeScript("get-block-offset")
expect(newOffset).toBe(String(offset))
expect(newOffset).toBe(offset)
})
})

Expand Down
2 changes: 1 addition & 1 deletion examples/03-deploy-contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("deploy contract", async () => {
}
}
`
const args = [1337]
const args = ["1337"]

await shallPass(deployContract({to, name, code, args}))

Expand Down
2 changes: 1 addition & 1 deletion examples/07-block-offset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test("block offset", async () => {
expect(normalResult).toBe("1")

// Offset current block height by 42
await setBlockOffset(42)
await setBlockOffset("42")
// Let's check that offset value on Manager is actually changed to 42
const [blockOffset] = await getBlockOffset()
expect(blockOffset).toBe("42")
Expand Down
6 changes: 3 additions & 3 deletions examples/08-execute-script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ test("execute script", async () => {

// args is just an array of values in the same order as they are defined in script code
const args = [
1337,
"1337",
true,
"Hello, Cadence",
"1.337",
[1, 3, 3, 7],
["1", "3", "3", "7"],
{
name: "Cadence",
status: "active",
},
42,
"42",
]
const name = "log-args"

Expand Down
2 changes: 1 addition & 1 deletion examples/101-pass-int-dictionary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("pass int dictionary", async () => {
}
`

const args = [{0: 1, 1: 42}, 1]
const args = [{0: "1", 1: "42"}, "1"]

const [result] = await shallResolve(executeScript({code, args}))
expect(result).toBe("42")
Expand Down
2 changes: 1 addition & 1 deletion examples/102-pass-string-to-int-dictionary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("pass string to int dictionary", async () => {
}
`

const args = [{cadence: 0, test: 1337}, "cadence"]
const args = [{cadence: "0", test: "1337"}, "cadence"]

const [result] = await shallResolve(executeScript({code, args}))
expect(result).toBe("0")
Expand Down