|
1 | | -import test from 'ava' |
2 | | -import { root, rpcUrl, signer } from './util.js' |
3 | | -import { Client, networks, contract as ContractClient } from 'test-custom-types' |
| 1 | +import test from "ava"; |
| 2 | +import { root, rpcUrl, signer } from "./util.js"; |
| 3 | +import { |
| 4 | + Client, |
| 5 | + networks, |
| 6 | + contract as ContractClient, |
| 7 | +} from "test-custom-types"; |
4 | 8 |
|
5 | 9 | const publicKey = root.keypair.publicKey(); |
6 | 10 |
|
7 | 11 | const contract = new Client({ |
8 | | - ...networks.standalone, |
| 12 | + ...networks.local, |
9 | 13 | rpcUrl, |
10 | 14 | allowHttp: true, |
11 | 15 | publicKey: root.keypair.publicKey(), |
12 | 16 | ...signer, |
13 | 17 | }); |
14 | 18 |
|
15 | | -test('hello', async t => { |
16 | | - const { result } = await contract.hello({ hello: 'tests' }) |
17 | | - t.is(result, 'tests') |
18 | | -}) |
| 19 | +test("hello", async (t) => { |
| 20 | + const { result } = await contract.hello({ hello: "tests" }); |
| 21 | + t.is(result, "tests"); |
| 22 | +}); |
19 | 23 |
|
20 | | -test('woid', async t => { |
21 | | - t.is((await contract.woid()).result, null) |
22 | | -}) |
| 24 | +test("woid", async (t) => { |
| 25 | + t.is((await contract.woid()).result, null); |
| 26 | +}); |
23 | 27 |
|
24 | | -test('u32_fail_on_even', async t => { |
| 28 | +test("u32_fail_on_even", async (t) => { |
25 | 29 | t.deepEqual( |
26 | 30 | (await contract.u32_fail_on_even({ u32_: 1 })).result, |
27 | | - new ContractClient.Ok(1) |
28 | | - ) |
| 31 | + new ContractClient.Ok(1), |
| 32 | + ); |
29 | 33 | t.deepEqual( |
30 | 34 | (await contract.u32_fail_on_even({ u32_: 0 })).result, |
31 | | - new ContractClient.Err({ message: "Please provide an odd number" }) |
32 | | - ) |
33 | | -}) |
| 35 | + new ContractClient.Err({ message: "Please provide an odd number" }), |
| 36 | + ); |
| 37 | +}); |
34 | 38 |
|
35 | | -test('u32_', async t => { |
36 | | - t.is((await contract.u32_({ u32_: 1 })).result, 1) |
37 | | -}) |
| 39 | +test("u32_", async (t) => { |
| 40 | + t.is((await contract.u32_({ u32_: 1 })).result, 1); |
| 41 | +}); |
38 | 42 |
|
39 | | -test('i32_', async t => { |
40 | | - t.is((await contract.i32_({ i32_: 1 })).result, 1) |
41 | | -}) |
| 43 | +test("i32_", async (t) => { |
| 44 | + t.is((await contract.i32_({ i32_: 1 })).result, 1); |
| 45 | +}); |
42 | 46 |
|
43 | | -test('i64_', async t => { |
44 | | - t.is((await contract.i64_({ i64_: 1n })).result, 1n) |
45 | | -}) |
| 47 | +test("i64_", async (t) => { |
| 48 | + t.is((await contract.i64_({ i64_: 1n })).result, 1n); |
| 49 | +}); |
46 | 50 |
|
47 | 51 | test("strukt_hel", async (t) => { |
48 | | - const test = { a: 0, b: true, c: "world" } |
49 | | - t.deepEqual((await contract.strukt_hel({ strukt: test })).result, ["Hello", "world"]) |
50 | | -}) |
| 52 | + const test = { a: 0, b: true, c: "world" }; |
| 53 | + t.deepEqual((await contract.strukt_hel({ strukt: test })).result, [ |
| 54 | + "Hello", |
| 55 | + "world", |
| 56 | + ]); |
| 57 | +}); |
51 | 58 |
|
52 | 59 | test("strukt", async (t) => { |
53 | | - const test = { a: 0, b: true, c: "hello" } |
54 | | - t.deepEqual((await contract.strukt({ strukt: test })).result, test) |
55 | | -}) |
56 | | - |
57 | | -test('simple first', async t => { |
58 | | - const arg = { tag: 'First', values: undefined } as const |
59 | | - const ret = { tag: 'First' } |
60 | | - t.deepEqual((await contract.simple({ simple: arg })).result, ret) |
61 | | -}) |
62 | | - |
63 | | -test('simple second', async t => { |
64 | | - const arg = { tag: 'Second', values: undefined } as const |
65 | | - const ret = { tag: 'Second' } |
66 | | - t.deepEqual((await contract.simple({ simple: arg })).result, ret) |
67 | | -}) |
68 | | - |
69 | | -test('simple third', async t => { |
70 | | - const arg = { tag: 'Third', values: undefined } as const |
71 | | - const ret = { tag: 'Third' } |
72 | | - t.deepEqual((await contract.simple({ simple: arg })).result, ret) |
73 | | -}) |
74 | | - |
75 | | -test('complex with struct', async t => { |
76 | | - const arg = { tag: 'Struct', values: [{ a: 0, b: true, c: 'hello' }] } as const |
77 | | - const ret = { tag: 'Struct', values: [{ a: 0, b: true, c: 'hello' }] } |
78 | | - t.deepEqual((await contract.complex({ complex: arg })).result, ret) |
79 | | -}) |
80 | | - |
81 | | -test('complex with tuple', async t => { |
82 | | - const arg = { tag: 'Tuple', values: [[{ a: 0, b: true, c: 'hello' }, { tag: 'First', values: undefined }]] } as const |
83 | | - const ret = { tag: 'Tuple', values: [[{ a: 0, b: true, c: 'hello' }, { tag: 'First' }]] } |
84 | | - t.deepEqual((await contract.complex({ complex: arg })).result, ret) |
85 | | -}) |
86 | | - |
87 | | -test('complex with enum', async t => { |
88 | | - const arg = { tag: 'Enum', values: [{ tag: 'First', values: undefined }] } as const |
89 | | - const ret = { tag: 'Enum', values: [{ tag: 'First' }] } |
90 | | - t.deepEqual((await contract.complex({ complex: arg })).result, ret) |
91 | | -}) |
92 | | - |
93 | | -test('complex with asset', async t => { |
94 | | - const arg = { tag: 'Asset', values: [publicKey, 1n] } as const |
95 | | - const ret = { tag: 'Asset', values: [publicKey, 1n] } |
96 | | - t.deepEqual((await contract.complex({ complex: arg })).result, ret) |
97 | | -}) |
98 | | - |
99 | | -test('complex with void', async t => { |
100 | | - const arg = { tag: 'Void', values: undefined } as const |
101 | | - const ret = { tag: 'Void' } |
102 | | - t.deepEqual((await contract.complex({ complex: arg })).result, ret) |
103 | | -}) |
104 | | - |
105 | | -test('addresse', async t => { |
106 | | - t.deepEqual((await contract.addresse({ addresse: publicKey })).result, publicKey) |
107 | | -}) |
108 | | - |
109 | | -test('bytes', async t => { |
110 | | - const bytes = Buffer.from('hello') |
111 | | - t.deepEqual((await contract.bytes({ bytes })).result, bytes) |
112 | | -}) |
113 | | - |
114 | | -test('bytes_n', async t => { |
115 | | - const bytes_n = Buffer.from('123456789') // what's the correct way to construct bytes_n? |
116 | | - t.deepEqual((await contract.bytes_n({ bytes_n })).result, bytes_n) |
117 | | -}) |
118 | | - |
119 | | -test('card', async t => { |
120 | | - const card = 11 |
121 | | - t.is((await contract.card({ card })).result, card) |
122 | | -}) |
123 | | - |
124 | | -test('boolean', async t => { |
125 | | - t.is((await contract.boolean({ boolean: true })).result, true) |
126 | | -}) |
127 | | - |
128 | | -test('not', async t => { |
129 | | - t.is((await contract.not({ boolean: true })).result, false) |
130 | | -}) |
131 | | - |
132 | | -test('i128', async t => { |
133 | | - t.is((await contract.i128({ i128: -1n })).result, -1n) |
134 | | -}) |
135 | | - |
136 | | -test('u128', async t => { |
137 | | - t.is((await contract.u128({ u128: 1n })).result, 1n) |
138 | | -}) |
139 | | - |
140 | | -test('multi_args', async t => { |
141 | | - t.is((await contract.multi_args({ a: 1, b: true })).result, 1) |
142 | | - t.is((await contract.multi_args({ a: 1, b: false })).result, 0) |
143 | | -}) |
144 | | - |
145 | | -test('map', async t => { |
146 | | - const map = new Map() |
147 | | - map.set(1, true) |
148 | | - map.set(2, false) |
| 60 | + const test = { a: 0, b: true, c: "hello" }; |
| 61 | + t.deepEqual((await contract.strukt({ strukt: test })).result, test); |
| 62 | +}); |
| 63 | + |
| 64 | +test("simple first", async (t) => { |
| 65 | + const arg = { tag: "First", values: undefined } as const; |
| 66 | + const ret = { tag: "First" }; |
| 67 | + t.deepEqual((await contract.simple({ simple: arg })).result, ret); |
| 68 | +}); |
| 69 | + |
| 70 | +test("simple second", async (t) => { |
| 71 | + const arg = { tag: "Second", values: undefined } as const; |
| 72 | + const ret = { tag: "Second" }; |
| 73 | + t.deepEqual((await contract.simple({ simple: arg })).result, ret); |
| 74 | +}); |
| 75 | + |
| 76 | +test("simple third", async (t) => { |
| 77 | + const arg = { tag: "Third", values: undefined } as const; |
| 78 | + const ret = { tag: "Third" }; |
| 79 | + t.deepEqual((await contract.simple({ simple: arg })).result, ret); |
| 80 | +}); |
| 81 | + |
| 82 | +test("complex with struct", async (t) => { |
| 83 | + const arg = { |
| 84 | + tag: "Struct", |
| 85 | + values: [{ a: 0, b: true, c: "hello" }], |
| 86 | + } as const; |
| 87 | + const ret = { tag: "Struct", values: [{ a: 0, b: true, c: "hello" }] }; |
| 88 | + t.deepEqual((await contract.complex({ complex: arg })).result, ret); |
| 89 | +}); |
| 90 | + |
| 91 | +test("complex with tuple", async (t) => { |
| 92 | + const arg = { |
| 93 | + tag: "Tuple", |
| 94 | + values: [ |
| 95 | + [ |
| 96 | + { a: 0, b: true, c: "hello" }, |
| 97 | + { tag: "First", values: undefined }, |
| 98 | + ], |
| 99 | + ], |
| 100 | + } as const; |
| 101 | + const ret = { |
| 102 | + tag: "Tuple", |
| 103 | + values: [[{ a: 0, b: true, c: "hello" }, { tag: "First" }]], |
| 104 | + }; |
| 105 | + t.deepEqual((await contract.complex({ complex: arg })).result, ret); |
| 106 | +}); |
| 107 | + |
| 108 | +test("complex with enum", async (t) => { |
| 109 | + const arg = { |
| 110 | + tag: "Enum", |
| 111 | + values: [{ tag: "First", values: undefined }], |
| 112 | + } as const; |
| 113 | + const ret = { tag: "Enum", values: [{ tag: "First" }] }; |
| 114 | + t.deepEqual((await contract.complex({ complex: arg })).result, ret); |
| 115 | +}); |
| 116 | + |
| 117 | +test("complex with asset", async (t) => { |
| 118 | + const arg = { tag: "Asset", values: [publicKey, 1n] } as const; |
| 119 | + const ret = { tag: "Asset", values: [publicKey, 1n] }; |
| 120 | + t.deepEqual((await contract.complex({ complex: arg })).result, ret); |
| 121 | +}); |
| 122 | + |
| 123 | +test("complex with void", async (t) => { |
| 124 | + const arg = { tag: "Void", values: undefined } as const; |
| 125 | + const ret = { tag: "Void" }; |
| 126 | + t.deepEqual((await contract.complex({ complex: arg })).result, ret); |
| 127 | +}); |
| 128 | + |
| 129 | +test("addresse", async (t) => { |
| 130 | + t.deepEqual( |
| 131 | + (await contract.addresse({ addresse: publicKey })).result, |
| 132 | + publicKey, |
| 133 | + ); |
| 134 | +}); |
| 135 | + |
| 136 | +test("bytes", async (t) => { |
| 137 | + const bytes = Buffer.from("hello"); |
| 138 | + t.deepEqual((await contract.bytes({ bytes })).result, bytes); |
| 139 | +}); |
| 140 | + |
| 141 | +test("bytes_n", async (t) => { |
| 142 | + const bytes_n = Buffer.from("123456789"); // what's the correct way to construct bytes_n? |
| 143 | + t.deepEqual((await contract.bytes_n({ bytes_n })).result, bytes_n); |
| 144 | +}); |
| 145 | + |
| 146 | +test("card", async (t) => { |
| 147 | + const card = 11; |
| 148 | + t.is((await contract.card({ card })).result, card); |
| 149 | +}); |
| 150 | + |
| 151 | +test("boolean", async (t) => { |
| 152 | + t.is((await contract.boolean({ boolean: true })).result, true); |
| 153 | +}); |
| 154 | + |
| 155 | +test("not", async (t) => { |
| 156 | + t.is((await contract.not({ boolean: true })).result, false); |
| 157 | +}); |
| 158 | + |
| 159 | +test("i128", async (t) => { |
| 160 | + t.is((await contract.i128({ i128: -1n })).result, -1n); |
| 161 | +}); |
| 162 | + |
| 163 | +test("u128", async (t) => { |
| 164 | + t.is((await contract.u128({ u128: 1n })).result, 1n); |
| 165 | +}); |
| 166 | + |
| 167 | +test("multi_args", async (t) => { |
| 168 | + t.is((await contract.multi_args({ a: 1, b: true })).result, 1); |
| 169 | + t.is((await contract.multi_args({ a: 1, b: false })).result, 0); |
| 170 | +}); |
| 171 | + |
| 172 | +test("map", async (t) => { |
| 173 | + const map = new Map(); |
| 174 | + map.set(1, true); |
| 175 | + map.set(2, false); |
149 | 176 | // map.set(3, 'hahaha') // should throw an error |
150 | | - const ret = Array.from(map.entries()) |
151 | | - t.deepEqual((await contract.map({ map })).result, ret) |
152 | | -}) |
| 177 | + const ret = Array.from(map.entries()); |
| 178 | + t.deepEqual((await contract.map({ map })).result, ret); |
| 179 | +}); |
153 | 180 |
|
154 | | -test('vec', async t => { |
155 | | - const vec = [1, 2, 3] |
156 | | - t.deepEqual((await contract.vec({ vec })).result, vec) |
157 | | -}) |
| 181 | +test("vec", async (t) => { |
| 182 | + const vec = [1, 2, 3]; |
| 183 | + t.deepEqual((await contract.vec({ vec })).result, vec); |
| 184 | +}); |
158 | 185 |
|
159 | | -test('tuple', async t => { |
160 | | - const tuple = ['hello', 1] as const |
161 | | - t.deepEqual((await contract.tuple({ tuple })).result, tuple) |
162 | | -}) |
| 186 | +test("tuple", async (t) => { |
| 187 | + const tuple = ["hello", 1] as const; |
| 188 | + t.deepEqual((await contract.tuple({ tuple })).result, tuple); |
| 189 | +}); |
163 | 190 |
|
164 | | -test('option', async t => { |
| 191 | +test("option", async (t) => { |
165 | 192 | // this makes sense |
166 | | - t.deepEqual((await contract.option({ option: 1 })).result, 1) |
| 193 | + t.deepEqual((await contract.option({ option: 1 })).result, 1); |
167 | 194 |
|
168 | 195 | // this passes but shouldn't |
169 | | - t.deepEqual((await contract.option({ option: undefined })).result, undefined) |
| 196 | + t.deepEqual((await contract.option({ option: undefined })).result, undefined); |
170 | 197 |
|
171 | 198 | // this is the behavior we probably want, but fails |
172 | 199 | // t.deepEqual(await contract.option(), undefined) // typing and implementation require the object |
173 | 200 | // t.deepEqual((await contract.option({})).result, undefined) // typing requires argument; implementation would be fine with this |
174 | 201 | // t.deepEqual((await contract.option({ option: undefined })).result, undefined) |
175 | | -}) |
| 202 | +}); |
176 | 203 |
|
177 | | -test('u256', async t => { |
178 | | - t.is((await contract.u256({ u256: 1n })).result, 1n) |
179 | | -}) |
| 204 | +test("u256", async (t) => { |
| 205 | + t.is((await contract.u256({ u256: 1n })).result, 1n); |
| 206 | +}); |
180 | 207 |
|
181 | | -test('i256', async t => { |
182 | | - t.is((await contract.i256({ i256: -1n })).result, -1n) |
183 | | -}) |
| 208 | +test("i256", async (t) => { |
| 209 | + t.is((await contract.i256({ i256: -1n })).result, -1n); |
| 210 | +}); |
184 | 211 |
|
185 | | -test('string', async t => { |
186 | | - t.is((await contract.string({ string: 'hello' })).result, 'hello') |
187 | | -}) |
| 212 | +test("string", async (t) => { |
| 213 | + t.is((await contract.string({ string: "hello" })).result, "hello"); |
| 214 | +}); |
188 | 215 |
|
189 | | -test('tuple_strukt', async t => { |
190 | | - const arg = [{ a: 0, b: true, c: 'hello' }, { tag: 'First', values: undefined }] as const |
191 | | - const res = [{ a: 0, b: true, c: 'hello' }, { tag: 'First' }] |
192 | | - t.deepEqual((await contract.tuple_strukt({ tuple_strukt: arg })).result, res) |
193 | | -}) |
| 216 | +test("tuple_strukt", async (t) => { |
| 217 | + const arg = [ |
| 218 | + { a: 0, b: true, c: "hello" }, |
| 219 | + { tag: "First", values: undefined }, |
| 220 | + ] as const; |
| 221 | + const res = [{ a: 0, b: true, c: "hello" }, { tag: "First" }]; |
| 222 | + t.deepEqual((await contract.tuple_strukt({ tuple_strukt: arg })).result, res); |
| 223 | +}); |
0 commit comments