Skip to content

Commit 0541838

Browse files
committed
Fix integration tests for struct-based creates
1 parent 32977d4 commit 0541838

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

packages/templates/next-export-ui/test-scaffold/tests/contract/integration.mjs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ function sampleValue(field, idx, forUpdate, accountAddress) {
7474
}
7575
}
7676

77+
function buildCreateInput(fields, accountAddress) {
78+
const input = {};
79+
for (const [idx, field] of fields.entries()) {
80+
input[field.name] = sampleValue(field, idx, false, accountAddress);
81+
}
82+
return input;
83+
}
84+
7785
async function mustFail(promiseFactory, expectedHint) {
7886
let failed = false;
7987
try {
@@ -135,20 +143,20 @@ async function main() {
135143
const deleteFn = `delete${name}`;
136144
const transferFn = `transfer${name}`;
137145

138-
const createArgs = fields.map((f, idx) => sampleValue(f, idx, false, account.address));
146+
const createInput = buildCreateInput(fields, account.address);
139147

140148
if (hasPayment) {
141149
await mustFail(() =>
142-
app.methods[createFn](...createArgs).send({ from: account.address, gas: 3_000_000 })
150+
app.methods[createFn](createInput).send({ from: account.address, gas: 3_000_000 })
143151
);
144152

145-
await app.methods[createFn](...createArgs).send({
153+
await app.methods[createFn](createInput).send({
146154
from: account.address,
147155
gas: 3_000_000,
148156
value: String(collection.createRules.payment.amountWei)
149157
});
150158
} else {
151-
await app.methods[createFn](...createArgs).send({ from: account.address, gas: 3_000_000 });
159+
await app.methods[createFn](createInput).send({ from: account.address, gas: 3_000_000 });
152160
}
153161

154162
const ids = await app.methods[listFn](0, 20, false).call();

test/integration/testCliLocalIntegration.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'fs';
33
import os from 'os';
44
import path from 'path';
55
import { spawn, spawnSync } from 'child_process';
6+
import Web3 from 'web3';
67

78
function writeJson(filePath, value) {
89
fs.mkdirSync(path.dirname(filePath), { recursive: true });
@@ -144,9 +145,9 @@ describe('CLI local integration (anvil + preview + relay)', function () {
144145
const createFn = (compiled?.abi ?? []).find((x) => x && x.type === 'function' && x.name === 'createCandidate');
145146
expect(createFn).to.be.ok;
146147

147-
const web3AbiMod = await import('web3-eth-abi');
148-
const web3Abi = web3AbiMod.default ?? web3AbiMod;
149-
const calldata = web3Abi.encodeFunctionCall(createFn, [{ name: 'Relay User' }]);
148+
const web3 = new Web3();
149+
const contract = new web3.eth.Contract(compiled.abi, contractAddress);
150+
const calldata = contract.methods.createCandidate({ name: 'Relay User' }).encodeABI();
150151

151152
const relaySubmit = await requestJson(`${baseUrl}/__tokenhost/relay`, {
152153
method: 'POST',

0 commit comments

Comments
 (0)