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

Commit 4639dfb

Browse files
author
Maksim Daunarovich
authored
Fix getContractAddress method (#66)
* Add test to check contract value after deployment * Use tuple for executeScript result * Fix interaction test * Bump version
1 parent f19756f commit 4639dfb

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

dev-test/deploy.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path";
22
import {
33
emulator,
44
init,
5+
executeScript,
56
deployContractByName,
67
getContractAddress,
78
getAccountAddress,
@@ -56,4 +57,20 @@ describe("interactions - sendTransaction", () => {
5657
const [ address ] = await getContractAddress(name);
5758
expect(address).toBe(Alice);
5859
});
60+
61+
test("deploy basic contract - check", async () => {
62+
const name = "HelloWorld";
63+
await deployContractByName(name);
64+
const [result, err] = await executeScript({
65+
code: `
66+
import HelloWorld from 0x1
67+
68+
pub fun main():String{
69+
return HelloWorld.message
70+
}
71+
`
72+
})
73+
expect(err).toBe(null)
74+
expect(result).toBe("Hello, from Cadence")
75+
});
5976
});

dev-test/interaction.test.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,33 @@ describe("interactions - executeScript", () => {
167167
});
168168

169169
test("executeScript - shall pass with short notation", async () => {
170-
const [result] = await shallResolve(executeScript("log-message"));
170+
const [result,err] = await shallResolve(executeScript("log-message"));
171+
expect(err).toBe(null);
171172
expect(result).toBe(42);
172173
});
173174

174175
test("executeScript - shall pass with short notation and arguments", async () => {
175176
const message = "Hello, from Cadence!";
176-
const [result] = await shallResolve(() => {
177+
const [result, err] = await shallResolve(() => {
177178
const args = [message];
178179
return executeScript("log-passed-message", args);
179180
});
181+
expect(err).toBe(null);
180182
expect(result).toBe(message);
181183
});
182184

183185
test("executeScript - shall work properly for empty array as argument", async () => {
184-
const code = `
186+
const [result, err] = await shallResolve(async () => {
187+
const code = `
185188
pub fun main(data: [String]): [String]{
186189
log(data)
187190
return data
188191
}
189192
`;
190-
const args = [[]];
191-
const result = await executeScript({ code, args });
193+
const args = [[]];
194+
return executeScript({ code, args });
195+
})
196+
expect(err).toBe(null);
192197
expect(result.length).toBe(0);
193198
});
194199
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flow-js-testing",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "This package will expose a set of utility methods, to allow Cadence code testing with libraries like Jest",
55
"repository": {
66
"type": "git",

src/contract.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const getContractAddress = async (name, useDefaults = false) => {
4646

4747
const code = await registry.scripts.getContractAddressTemplate(addressMap);
4848
const args = [name, managerAddress];
49-
const contractAddress = await executeScript({
49+
const [contractAddress] = await executeScript({
5050
code,
5151
args,
5252
service: true,

0 commit comments

Comments
 (0)