Skip to content

Commit 6d3b0a8

Browse files
test: Add contract tests (#3307)
Signed-off-by: Mario Dimitrov <[email protected]>
1 parent 717873b commit 6d3b0a8

File tree

2 files changed

+148
-6
lines changed

2 files changed

+148
-6
lines changed

test/integration/ContractUpdateIntegrationTest.js

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FileDeleteTransaction,
99
Hbar,
1010
Status,
11+
AccountId,
1112
} from "../../src/exports.js";
1213
import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js";
1314

@@ -41,9 +42,7 @@ describe("ContractUpdate", function () {
4142
.setAdminKey(operatorKey)
4243
.setGas(300_000)
4344
.setConstructorParameters(
44-
new ContractFunctionParameters().addString(
45-
"Hello from Hedera.",
46-
),
45+
new ContractFunctionParameters().addString("Hello from Hiero."),
4746
)
4847
.setBytecodeFileId(file)
4948
.setContractMemo("[e2e::ContractCreateTransaction]")
@@ -136,9 +135,7 @@ describe("ContractUpdate", function () {
136135
.setAdminKey(operatorKey)
137136
.setGas(300_000)
138137
.setConstructorParameters(
139-
new ContractFunctionParameters().addString(
140-
"Hello from Hedera.",
141-
),
138+
new ContractFunctionParameters().addString("Hello from Hiero."),
142139
)
143140
.setBytecodeFileId(file)
144141
.setContractMemo("[e2e::ContractCreateTransaction]")
@@ -182,6 +179,108 @@ describe("ContractUpdate", function () {
182179
}
183180
});
184181

182+
it("should update the auto renew account ID to 0.0.0", async function () {
183+
const operatorKey = env.operatorKey.publicKey;
184+
185+
let response = await new FileCreateTransaction()
186+
.setKeys([operatorKey])
187+
.setContents(smartContractBytecode)
188+
.execute(env.client);
189+
190+
let receipt = await response.getReceipt(env.client);
191+
192+
expect(receipt.fileId).to.not.be.null;
193+
expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be
194+
.true;
195+
196+
const file = receipt.fileId;
197+
198+
response = await new ContractCreateTransaction()
199+
.setAdminKey(operatorKey)
200+
.setGas(300_000)
201+
.setConstructorParameters(
202+
new ContractFunctionParameters().addString("Hello from Hiero."),
203+
)
204+
.setBytecodeFileId(file)
205+
.setContractMemo("[e2e::ContractCreateTransaction]")
206+
.setAutoRenewAccountId(env.client.operatorAccountId)
207+
.execute(env.client);
208+
209+
receipt = await response.getReceipt(env.client);
210+
console.log("contract");
211+
212+
expect(receipt.contractId).to.not.be.null;
213+
expect(receipt.contractId != null ? receipt.contractId.num > 0 : false)
214+
.to.be.true;
215+
216+
let contract = receipt.contractId;
217+
218+
let info = await new ContractInfoQuery()
219+
.setContractId(contract)
220+
.setQueryPayment(new Hbar(1))
221+
.execute(env.client);
222+
223+
expect(info.contractId.toString()).to.be.equal(contract.toString());
224+
expect(info.accountId).to.be.not.null;
225+
expect(
226+
info.contractId != null ? info.contractId.toString() : "",
227+
).to.be.equal(contract.toString());
228+
expect(info.adminKey).to.be.not.null;
229+
expect(
230+
info.adminKey != null ? info.adminKey.toString() : "",
231+
).to.be.equal(operatorKey.toString());
232+
expect(info.storage.toInt()).to.be.equal(128);
233+
expect(info.contractMemo).to.be.equal(
234+
"[e2e::ContractCreateTransaction]",
235+
);
236+
expect(info.autoRenewAccountId.toString()).to.be.equal(
237+
env.client.operatorAccountId.toString(),
238+
);
239+
240+
await (
241+
await new ContractUpdateTransaction()
242+
.setContractId(contract)
243+
.setContractMemo("[e2e::ContractUpdateTransaction]")
244+
.setAutoRenewAccountId(new AccountId(0, 0, 0))
245+
.execute(env.client)
246+
).getReceipt(env.client);
247+
248+
info = await new ContractInfoQuery()
249+
.setContractId(contract)
250+
.setQueryPayment(new Hbar(5))
251+
.execute(env.client);
252+
253+
expect(info.contractId.toString()).to.be.equal(contract.toString());
254+
expect(info.accountId).to.be.not.null;
255+
expect(
256+
info.contractId != null ? info.contractId.toString() : "",
257+
).to.be.equal(contract.toString());
258+
expect(info.adminKey).to.be.not.null;
259+
expect(
260+
info.adminKey != null ? info.adminKey.toString() : "",
261+
).to.be.equal(operatorKey.toString());
262+
expect(info.storage.toInt()).to.be.equal(128);
263+
expect(info.contractMemo).to.be.equal(
264+
"[e2e::ContractUpdateTransaction]",
265+
);
266+
expect(info.autoRenewAccountId.toString()).to.be.equal(
267+
new AccountId(0, 0, 0).toString(),
268+
);
269+
270+
await (
271+
await new ContractDeleteTransaction()
272+
.setContractId(contract)
273+
.setTransferAccountId(env.client.operatorAccountId)
274+
.execute(env.client)
275+
).getReceipt(env.client);
276+
277+
await (
278+
await new FileDeleteTransaction()
279+
.setFileId(file)
280+
.execute(env.client)
281+
).getReceipt(env.client);
282+
});
283+
185284
afterAll(async function () {
186285
await env.close();
187286
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { AccountId, ContractCreateTransaction } from "../../src/index.js";
2+
import Long from "long";
3+
4+
describe("ContractCreateTransaction", function () {
5+
let stakedAccountId;
6+
let stakedNodeId;
7+
8+
beforeEach(function () {
9+
stakedAccountId = new AccountId(0, 0, 3333);
10+
stakedNodeId = Long.fromNumber(5);
11+
});
12+
13+
it("should throw an error if gas is negative", function () {
14+
const tx = new ContractCreateTransaction();
15+
16+
let err = false;
17+
try {
18+
tx.setGas(-1);
19+
} catch (error) {
20+
if (error.message.includes("Gas cannot be negative number"))
21+
err = true;
22+
}
23+
24+
expect(err).to.be.true;
25+
});
26+
27+
it("should get the last called if both stakedAccountId and stakedNodeId are present", function () {
28+
const tx = new ContractCreateTransaction({
29+
stakedAccountId: stakedAccountId,
30+
stakedNodeId: stakedNodeId,
31+
});
32+
33+
expect(tx.stakedAccountId).to.be.null;
34+
expect(tx.stakedNodeId.toString()).to.equal(stakedNodeId.toString());
35+
36+
tx.setStakedAccountId(stakedAccountId);
37+
38+
expect(tx.stakedAccountId.toString()).to.equal(
39+
stakedAccountId.toString(),
40+
);
41+
expect(tx.stakedNodeId).to.be.null;
42+
});
43+
});

0 commit comments

Comments
 (0)