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

Commit f905016

Browse files
authored
Fix passing numbers as values deprecation notice (#188)
* Fix numbers as values deprecation for tests * Add changeset
1 parent 8d75426 commit f905016

11 files changed

+43
-36
lines changed

.changeset/sweet-penguins-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/flow-js-testing": patch
3+
---
4+
5+
Fix numbers as values deprecation warnings for tests

dev-test/deploy.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe("interactions - sendTransaction", () => {
8484

8585
test("deploy custom contract with arguments", async () => {
8686
const message = "Hello, Cadence"
87-
const number = 42
87+
const number = "42"
8888
await shallPass(
8989
deployContract({
9090
code: `
@@ -128,7 +128,7 @@ describe("interactions - sendTransaction", () => {
128128
`,
129129
})
130130
)
131-
expect(numberResult).toBe(String(number))
131+
expect(numberResult).toBe(number)
132132
expect(numberErr).toBe(null)
133133
})
134134
})

dev-test/interaction.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe("interactions - sendTransaction", () => {
219219
}
220220
}
221221
`
222-
const args = [42]
222+
const args = ["42"]
223223
return sendTransaction({code, args})
224224
})
225225
})
@@ -233,7 +233,7 @@ describe("interactions - sendTransaction", () => {
233233
}
234234
}
235235
`
236-
const args = [42, 1337, "Hello, Cadence"]
236+
const args = ["42", "1337", "Hello, Cadence"]
237237
return sendTransaction({code, args})
238238
})
239239
})
@@ -247,7 +247,7 @@ describe("interactions - sendTransaction", () => {
247247
}
248248
}
249249
`
250-
const args = [42, 1337, "Hello, Cadence"]
250+
const args = ["42", "1337", "Hello, Cadence"]
251251
return sendTransaction({code, args})
252252
})
253253
})

dev-test/metadata.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ describe("metadata examples", () => {
3232
return metadata["answer"]!
3333
}
3434
`
35-
const answer = 42
35+
const answer = "42"
3636
const args = [{answer}]
3737
const [result] = await shallResolve(executeScript({code, args}))
38-
expect(result).toBe(String(answer))
38+
expect(result).toBe(answer)
3939
})
4040

4141
test("simple array - [String]", async () => {
@@ -60,12 +60,12 @@ describe("metadata examples", () => {
6060
return list[0][index]
6161
}
6262
`
63-
const value = [1, 3, 3, 7]
64-
const index = 3
63+
const value = ["1", "3", "3", "7"]
64+
const index = "3"
6565
const args = [[value], index]
6666

6767
const [result, err] = await executeScript({code, args})
68-
expect(result).toBe(String(value[index]))
68+
expect(result).toBe(value[index])
6969
expect(err).toBe(null)
7070
})
7171
})

dev-test/usage.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe("jest methods", () => {
112112
`,
113113
})
114114
)
115-
expect(result).toBe(String(42))
115+
expect(result).toBe("42")
116116
expect(err).toBe(null)
117117
})
118118

dev-test/utilities.test.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ describe("block height offset", () => {
4949
const [zeroOffset] = await executeScript("get-block-offset")
5050
expect(zeroOffset).toBe("0")
5151

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

5555
const [newOffset] = await executeScript("get-block-offset")
56-
expect(newOffset).toBe(String(offset))
56+
expect(newOffset).toBe(offset)
5757
})
5858

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

68-
const offset = 42
68+
const offset = "42"
6969
await shallPass(setBlockOffset(offset))
7070

7171
const [newOffset] = await getBlockOffset()
72-
expect(newOffset).toBe(String(offset))
72+
expect(newOffset).toBe(offset)
7373
})
7474

7575
it("should update offset in contract", async () => {
@@ -87,7 +87,7 @@ describe("block height offset", () => {
8787
})
8888
)
8989

90-
const offset = 42
90+
const offset = "42"
9191
await shallPass(manager.setBlockOffset(offset))
9292

9393
const realBlock = await query({
@@ -110,7 +110,7 @@ describe("block height offset", () => {
110110
)
111111

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

@@ -136,11 +136,11 @@ describe("block height offset utilities", () => {
136136
const [offset] = await shallResolve(manager.getBlockOffset())
137137
expect(offset).toBe("0")
138138

139-
const blockOffset = 42
139+
const blockOffset = "42"
140140
await shallPass(manager.setBlockOffset(blockOffset))
141141

142142
const [newOffset] = await shallResolve(manager.getBlockOffset())
143-
expect(newOffset).toBe(String(blockOffset))
143+
expect(newOffset).toBe(blockOffset)
144144
})
145145
})
146146

@@ -167,12 +167,12 @@ describe("timestamp offset", () => {
167167
const [zeroOffset] = await executeScript("get-timestamp-offset")
168168
expect(zeroOffset).toBe("0.00000000")
169169

170-
const offset = 42
170+
const offset = "42"
171171
await shallPass(
172172
sendTransaction("set-timestamp-offset", [manager], [offset])
173173
)
174174
const [newOffset] = await executeScript("get-timestamp-offset")
175-
expect(newOffset).toBe(offset.toFixed(8))
175+
expect(newOffset).toBe(Number(offset).toFixed(8))
176176
})
177177

178178
it("should read offset with utility method", async () => {
@@ -184,11 +184,11 @@ describe("timestamp offset", () => {
184184
const [oldOffset] = await getTimestampOffset()
185185
expect(oldOffset).toBe("0.00000000")
186186

187-
const offset = 42
187+
const offset = "42"
188188
await shallPass(setTimestampOffset(offset))
189189

190190
const [newOffset] = await getTimestampOffset()
191-
expect(newOffset).toBe(offset.toFixed(8))
191+
expect(newOffset).toBe(Number(offset).toFixed(8))
192192
})
193193

194194
it("should update offset in contract", async () => {
@@ -206,7 +206,7 @@ describe("timestamp offset", () => {
206206
})
207207
)
208208

209-
const offset = 42
209+
const offset = "42"
210210
await shallPass(manager.setTimestampOffset(offset))
211211

212212
const realTimestamp = await query({
@@ -228,7 +228,9 @@ describe("timestamp offset", () => {
228228
})
229229
)
230230

231-
expect(Number(currentTimestamp)).toBe(Number(realTimestamp) + offset)
231+
expect(Number(currentTimestamp)).toBe(
232+
Number(realTimestamp) + Number(offset)
233+
)
232234
})
233235
})
234236

@@ -254,11 +256,11 @@ describe("timestamp offset utilities", () => {
254256
const [offset] = await shallResolve(manager.getTimestampOffset())
255257
expect(offset).toBe("0.00000000")
256258

257-
const blockOffset = 42
259+
const blockOffset = "42"
258260
await shallPass(manager.setTimestampOffset(blockOffset))
259261

260262
const [newOffset] = await shallResolve(manager.getTimestampOffset())
261-
expect(newOffset).toBe(blockOffset.toFixed(8))
263+
expect(newOffset).toBe(Number(blockOffset).toFixed(8))
262264
})
263265
})
264266

@@ -281,11 +283,11 @@ describe("dev tests", () => {
281283
})
282284

283285
it("should return proper offset, when changed", async () => {
284-
const offset = 42
286+
const offset = "42"
285287
const manager = await getServiceAddress()
286288
await shallPass(sendTransaction("set-block-offset", [manager], [offset]))
287289
const [newOffset] = await executeScript("get-block-offset")
288-
expect(newOffset).toBe(String(offset))
290+
expect(newOffset).toBe(offset)
289291
})
290292
})
291293

examples/03-deploy-contract.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test("deploy contract", async () => {
2929
}
3030
}
3131
`
32-
const args = [1337]
32+
const args = ["1337"]
3333

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

examples/07-block-offset.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test("block offset", async () => {
3232
expect(normalResult).toBe("1")
3333

3434
// Offset current block height by 42
35-
await setBlockOffset(42)
35+
await setBlockOffset("42")
3636
// Let's check that offset value on Manager is actually changed to 42
3737
const [blockOffset] = await getBlockOffset()
3838
expect(blockOffset).toBe("42")

examples/08-execute-script.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ test("execute script", async () => {
2626

2727
// args is just an array of values in the same order as they are defined in script code
2828
const args = [
29-
1337,
29+
"1337",
3030
true,
3131
"Hello, Cadence",
3232
"1.337",
33-
[1, 3, 3, 7],
33+
["1", "3", "3", "7"],
3434
{
3535
name: "Cadence",
3636
status: "active",
3737
},
38-
42,
38+
"42",
3939
]
4040
const name = "log-args"
4141

examples/101-pass-int-dictionary.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test("pass int dictionary", async () => {
1515
}
1616
`
1717

18-
const args = [{0: 1, 1: 42}, 1]
18+
const args = [{0: "1", 1: "42"}, "1"]
1919

2020
const [result] = await shallResolve(executeScript({code, args}))
2121
expect(result).toBe("42")

examples/102-pass-string-to-int-dictionary.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test("pass string to int dictionary", async () => {
1515
}
1616
`
1717

18-
const args = [{cadence: 0, test: 1337}, "cadence"]
18+
const args = [{cadence: "0", test: "1337"}, "cadence"]
1919

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

0 commit comments

Comments
 (0)