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

Commit f19756f

Browse files
Maksim Daunarovichhichanajustjoolz
authored
FLIP Fest - Merge PR (#63)
* Code submission for FLIP fest 'JS Testing Feature: Multiple return values from interaction 30' (#57) * squash merge of TeamExponential work for flip 30 * add fixes to final submission requested by Max * add remaining fixes for Max feedback * get basic fixes done requested by Max * update all usage of args for sendTransaction to allow flow-cadut to to resolve types * update all points where executeScript is used to make sure args used correctly, allowing flow-cadut to resolve * remove fcl/types * revert package-lock.json to master plus package.json changes after running `npm install` * revert ports in tests back to 8080, remove testMatch for 'dev-test' in package.json * squash merge of latest changes per Max feedback * make package.json flow-cadut match recent release from Max * revert package-lock.json to master verion * update version in package.json to match Max release, run npm install to update package-lock * ran npm install * squash merge latest updates/fixes * replace package-lock.json * revert package-lock.json * remove try catch from tests * remove onflow/types * remove space * prettify * update cadut to release version * add fix to generated code to mitigate error running tests * ran prettify * re-add 'limit' prop and usage in interaction.js Co-authored-by: justjoolz <[email protected]> Co-authored-by: Maksim Daunarovich <[email protected]> * Bump version to next major release * Add release notes with breaking changes. Co-authored-by: Matt Chana <[email protected]> Co-authored-by: justjoolz <[email protected]>
1 parent fbe8432 commit f19756f

24 files changed

+270
-300
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.history
44
node_modules
55
dist
6+
.DS_Store

CHANGELOG.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1+
### 0.2.0
2+
3+
#### **BREAKING CHANGES**
4+
- `sendTransaction` and `executeScript` functions now return a tuple of [result, error]. As do the following functions:
5+
- updateContract
6+
- setBlockOffset
7+
- scratch
8+
- registerContract
9+
- mintTokens
10+
- initManager
11+
- deployContract
12+
- createAccount
13+
- setBlockOffset
14+
- mintFlow
15+
16+
- getManagerAddress
17+
- getContractAddress
18+
- getBlockOffset
19+
- getBalance
20+
- getAccountAddress
21+
- checkManager
22+
- getBlockOffset
23+
- getFlowBalance
24+
25+
26+
Any code that relies upon checking the result of any of these functions and expects only the result returned will need to be refactored.
27+
Jest asserts were updated accordingly, but if you were writing your own you will need to update them.
28+
For examples of new usage see the [script](/docs/exeute-scripts.md), [transaction](/docs/send-transactions.md) and [api](/docs/api.md) documentation.
29+
130
### 0.1.15
31+
232
- `limit` field added to script and transactions
333
- `flow-cadut` brings several improvements and fixes to parser
434

535
### 0.1.14 - 2021-09-08
6-
- Refactor FlowManager to include new block offset code
36+
37+
- Refactor FlowManager to include new block offset code
738
- Add code transformers functionality
839
- Add block offset functionality
940
- Add runnable examples
@@ -15,3 +46,4 @@
1546
- Bootstrap utility added to framework
1647
- Update `flow-cadut` dependency and fixed support for complex types
1748
- Fixed issue with emulator throwing an error with `logging` flag set to `true`
49+

dev-test/deploy.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
deployContractByName,
66
getContractAddress,
77
getAccountAddress,
8-
getServiceAddress,
8+
getServiceAddress
99
} from "../src";
1010

1111
// We need to set timeout for a higher number, cause some transactions might take up some time
@@ -28,15 +28,15 @@ describe("interactions - sendTransaction", () => {
2828
test("deploy basic contract - to service account", async () => {
2929
const name = "HelloWorld";
3030
await deployContractByName({ name });
31-
const address = await getContractAddress(name);
31+
const [ address ] = await getContractAddress(name);
3232
const serviceAccount = await getServiceAddress();
3333
expect(address).toBe(serviceAccount);
3434
});
3535

3636
test("deploy basic contract - to service account, short notation", async () => {
3737
const name = "HelloWorld";
3838
await deployContractByName(name);
39-
const address = await getContractAddress(name);
39+
const [ address ] = await getContractAddress(name);
4040
const serviceAccount = await getServiceAddress();
4141
expect(address).toBe(serviceAccount);
4242
});
@@ -45,15 +45,15 @@ describe("interactions - sendTransaction", () => {
4545
const Alice = await getAccountAddress("Alice");
4646
const name = "HelloWorld";
4747
await deployContractByName({ name, to: Alice });
48-
const address = await getContractAddress(name);
48+
const [ address ] = await getContractAddress(name);
4949
expect(address).toBe(Alice);
5050
});
5151

5252
test("deploy basic contract - to Alice account, short notation", async () => {
5353
const name = "HelloWorld";
5454
const Alice = await getAccountAddress("Alice");
5555
await deployContractByName(name, Alice);
56-
const address = await getContractAddress(name);
56+
const [ address ] = await getContractAddress(name);
5757
expect(address).toBe(Alice);
5858
});
5959
});

dev-test/imports.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ describe("import resolver", () => {
4040

4141
const addressMap = await resolveImports(code);
4242
const Registry = await getServiceAddress();
43-
expect(addressMap["First"]).toBe(Registry);
44-
expect(addressMap["Second"]).toBe(Registry);
43+
const [first] = addressMap["First"];
44+
const [second] = addressMap["Second"];
45+
expect(first).toBe(Registry);
46+
expect(second).toBe(Registry);
4547
expect(addressMap["FungibleToken"]).toBe(defaultsByName.FungibleToken);
4648
expect(addressMap["FlowToken"]).toBe(defaultsByName.FlowToken);
4749
});

dev-test/interaction.test.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from "path";
2-
import * as types from "@onflow/types";
32
import {
43
emulator,
54
init,
@@ -69,10 +68,11 @@ describe("interactions - sendTransaction", () => {
6968
}
7069
}
7170
`;
72-
const args = [[42, types.Int]];
71+
const args = [42];
7372
return sendTransaction({ code, args });
7473
});
7574
});
75+
7676
test("sendTransaction - argument mapper - multiple", async () => {
7777
await shallPass(async () => {
7878
const code = `
@@ -82,13 +82,11 @@ describe("interactions - sendTransaction", () => {
8282
}
8383
}
8484
`;
85-
const args = [
86-
[42, 1337, types.Int],
87-
["Hello, Cadence", types.String],
88-
];
85+
const args = [42, 1337, "Hello, Cadence"];
8986
return sendTransaction({ code, args });
9087
});
9188
});
89+
9290
test("sendTransaction - argument mapper - automatic", async () => {
9391
await shallPass(async () => {
9492
const code = `
@@ -99,7 +97,6 @@ describe("interactions - sendTransaction", () => {
9997
}
10098
`;
10199
const args = [42, 1337, "Hello, Cadence"];
102-
103100
return sendTransaction({ code, args });
104101
});
105102
});
@@ -170,13 +167,13 @@ describe("interactions - executeScript", () => {
170167
});
171168

172169
test("executeScript - shall pass with short notation", async () => {
173-
const result = await shallResolve(executeScript("log-message"));
170+
const [result] = await shallResolve(executeScript("log-message"));
174171
expect(result).toBe(42);
175172
});
176173

177174
test("executeScript - shall pass with short notation and arguments", async () => {
178175
const message = "Hello, from Cadence!";
179-
const result = await shallResolve(() => {
176+
const [result] = await shallResolve(() => {
180177
const args = [message];
181178
return executeScript("log-passed-message", args);
182179
});

dev-test/metadata.test.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("metadata examples", () => {
2323
`;
2424
const name = "Cadence";
2525
const args = [{ name }];
26-
const result = await shallResolve(executeScript({ code, args }));
26+
const [result] = await shallResolve(executeScript({ code, args }));
2727
expect(result).toBe(name);
2828
});
2929

@@ -35,7 +35,7 @@ describe("metadata examples", () => {
3535
`;
3636
const answer = 42;
3737
const args = [{ answer }];
38-
const result = await shallResolve(executeScript({ code, args }));
38+
const [result] = await shallResolve(executeScript({ code, args }));
3939
expect(result).toBe(answer);
4040
});
4141

@@ -47,7 +47,7 @@ describe("metadata examples", () => {
4747
`;
4848
const value = "test";
4949
const args = [[value]];
50-
const result = await shallResolve(executeScript({ code, args }));
50+
const [result] = await shallResolve(executeScript({ code, args }));
5151
expect(result).toBe(value);
5252
});
5353

@@ -65,11 +65,8 @@ describe("metadata examples", () => {
6565
const index = 3;
6666
const args = [[value], index];
6767

68-
try {
69-
const result = await executeScript({ code, args });
70-
expect(result).toBe(value[index]);
71-
} catch (e) {
72-
console.error(e);
73-
}
68+
const [result, err] = await executeScript({ code, args });
69+
expect(result).toBe(value[index]);
70+
expect(err).toBe(null);
7471
});
7572
});

dev-test/usage.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("Basic Usage test", () => {
4343
const addressMap = { HelloWorld: Alice };
4444
const code = await getScriptCode({ name: "get-message", addressMap });
4545
console.log({ code });
46-
const message = await executeScript({
46+
const [message] = await executeScript({
4747
code,
4848
});
4949
console.log({ message });

dev-test/utilities.test.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ describe("block height offset", () => {
3535
});
3636

3737
it("should return zero offset", async () => {
38-
const result = await executeScript("get-block-offset");
39-
expect(result).toBe(0);
38+
const [zeroOffset] = await executeScript("get-block-offset");
39+
expect(zeroOffset).toBe(0);
4040
});
4141

4242
it("should update offset", async () => {
4343
const manager = await getServiceAddress();
44-
const result = await executeScript("get-block-offset");
45-
expect(result).toBe(0);
44+
const [zeroOffset] = await executeScript("get-block-offset");
45+
expect(zeroOffset).toBe(0);
4646

4747
const offset = 42;
4848
await shallPass(sendTransaction("set-block-offset", [manager], [offset]));
49-
const newOffset = await executeScript("get-block-offset");
49+
const [newOffset] = await executeScript("get-block-offset");
5050
expect(newOffset).toBe(offset);
5151
});
5252

@@ -56,9 +56,10 @@ describe("block height offset", () => {
5656
const FlowManager = await getManagerAddress();
5757
const addressMap = { FlowManager };
5858

59-
const result = await getBlockOffset({ addressMap });
59+
const [offSet] = await getBlockOffset({ addressMap });
60+
61+
expect(offSet).toBe(0);
6062

61-
expect(result).toBe(0);
6263
});
6364

6465
it("should update offset with utility method", async () => {
@@ -67,15 +68,17 @@ describe("block height offset", () => {
6768
const FlowManager = await getManagerAddress();
6869
const addressMap = { FlowManager };
6970

70-
const oldOffset = await getBlockOffset({ addressMap });
71+
const [oldOffset] = await getBlockOffset({ addressMap });
72+
7173
expect(oldOffset).toBe(0);
7274

7375
const offset = 42;
7476

75-
const txResult = await setBlockOffset(offset);
77+
const [txResult] = await setBlockOffset(offset);
7678
expect(txResult.errorMessage).toBe("");
7779

78-
const newOffset = await getBlockOffset({ addressMap });
80+
const [newOffset] = await getBlockOffset({ addressMap });
81+
7982
expect(newOffset).toBe(offset);
8083
});
8184
});
@@ -95,18 +98,18 @@ describe("block height offset utilities", () => {
9598
});
9699

97100
it("should return 0 for initial block offset", async () => {
98-
const result = await shallResolve(manager.getBlockOffset());
99-
expect(result).toBe(0);
101+
const [initialOffset] = await shallResolve(manager.getBlockOffset());
102+
expect(initialOffset).toBe(0);
100103
});
101104

102105
it("should update block offset", async () => {
103-
const initialOffset = await shallResolve(manager.getBlockOffset());
104-
expect(initialOffset).toBe(0);
106+
const [offset] = await shallResolve(manager.getBlockOffset());
107+
expect(offset).toBe(0);
105108

106109
const blockOffset = 42;
107110
await shallPass(manager.setBlockOffset(blockOffset));
108111

109-
const newOffset = await shallResolve(manager.getBlockOffset());
112+
const [newOffset] = await shallResolve(manager.getBlockOffset());
110113
expect(newOffset).toBe(blockOffset);
111114
});
112115
});
@@ -126,15 +129,15 @@ describe("dev tests", () => {
126129
});
127130

128131
it("should return proper offset", async () => {
129-
const zeroOffset = await executeScript("get-block-offset");
132+
const [zeroOffset] = await executeScript("get-block-offset");
130133
expect(zeroOffset).toBe(0);
131134
});
132135

133136
it("should return proper offset, when changed", async () => {
134137
const offset = 42;
135138
const manager = await getServiceAddress();
136139
await shallPass(sendTransaction("set-block-offset", [manager], [offset]));
137-
const newOffset = await executeScript("get-block-offset");
140+
const [newOffset] = await executeScript("get-block-offset");
138141
expect(newOffset).toBe(offset);
139142
});
140143

@@ -153,7 +156,7 @@ describe("dev tests", () => {
153156

154157
const playgroundAddresses = ["0x01", "0x02", "0x03", "0x04", "0x05"];
155158
for (const i in playgroundAddresses) {
156-
const result = await executeScript({
159+
const [result] = await executeScript({
157160
code,
158161
transformers: [playgroundImport(accounts)],
159162
args: [playgroundAddresses[i]],

0 commit comments

Comments
 (0)