Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Jan 29, 2025
1 parent 5f45564 commit 2af7f14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
14 changes: 5 additions & 9 deletions src/abi/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from "../testutils";
import { Token, TokenTransfer } from "../tokens";
import { Transaction } from "../transaction";
import { TransactionComputer } from "../transactionComputer";
import { ContractFunction } from "./function";
import { Interaction } from "./interaction";
import { SmartContract } from "./smartContract";
Expand Down Expand Up @@ -249,27 +248,24 @@ describe("test smart contract interactor", function () {
let transaction = interaction.withSender(alice.address).withNonce(0n).buildTransaction();
transaction.setSender(alice.address);
transaction.applySignature(await alice.signer.sign(transaction.serializeForSigning()));
await provider.sendTransaction(transaction);
let hash = await provider.sendTransaction(transaction);
assert.equal(transaction.getNonce().valueOf(), 0n);
assert.equal(transaction.getData().toString(), "getUltimateAnswer");
const computer = new TransactionComputer();
let hashString = computer.computeTransactionHash(transaction);
assert.equal(hashString, "3579ad09099feb9755c860ddd225251170806d833342e912fccdfe2ed5c3a364");
assert.equal(hash, "3579ad09099feb9755c860ddd225251170806d833342e912fccdfe2ed5c3a364");

transaction = interaction.withNonce(1n).buildTransaction();
transaction.setSender(alice.address);
transaction.applySignature(await alice.signer.sign(transaction.serializeForSigning()));
await provider.sendTransaction(transaction);
hash = await provider.sendTransaction(transaction);
assert.equal(transaction.getNonce(), 1n);
hashString = computer.computeTransactionHash(transaction);
assert.equal(hashString, "ad513ce7c5d371d30e48f073326899766736eac1ac231d847d45bc3facbcb496");
assert.equal(hash, "ad513ce7c5d371d30e48f073326899766736eac1ac231d847d45bc3facbcb496");

// Execute, and wait for execution
transaction = interaction.withNonce(2n).buildTransaction();
transaction.setSender(alice.address);
transaction.applySignature(await alice.signer.sign(transaction.serializeForSigning()));
provider.mockGetTransactionWithAnyHashAsNotarizedWithOneResult("@6f6b@2bs", "getUltimateAnswer");
let hash = await provider.sendTransaction(transaction);
hash = await provider.sendTransaction(transaction);
let responseExecute = await controller.awaitCompletedExecute(hash);

assert.isTrue(responseExecute.values.length == 1);
Expand Down
4 changes: 1 addition & 3 deletions src/abi/smartContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ describe("test contract", () => {

// Now let's broadcast the deploy transaction, and wait for its execution.
let hash = await provider.sendTransaction(deployTransaction);
const computer = new TransactionComputer();
const hashString = computer.computeTransactionHash(deployTransaction);

await Promise.all([
provider.mockTransactionTimeline(deployTransaction, [
Expand All @@ -202,7 +200,7 @@ describe("test contract", () => {
new TransactionStatus("executed"),
new MarkCompleted(),
]),
watcher.awaitCompleted(hashString),
watcher.awaitCompleted(hash),
]);

assert.isTrue((await provider.getTransaction(hash)).status.isCompleted());
Expand Down
12 changes: 6 additions & 6 deletions src/transaction.local.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ describe("test transaction", function () {
await signTransaction({ transaction: transactionOne, wallet: alice });
await signTransaction({ transaction: transactionTwo, wallet: alice });

await provider.sendTransaction(transactionOne);
await provider.sendTransaction(transactionTwo);
const hashOne = await provider.sendTransaction(transactionOne);
const hashTwo = await provider.sendTransaction(transactionTwo);

await watcher.awaitCompleted(transactionOne.getHash().hex());
await watcher.awaitCompleted(transactionTwo.getHash().hex());
await watcher.awaitCompleted(hashOne);
await watcher.awaitCompleted(hashTwo);

await bob.sync(provider);
let newBalanceOfBob = new BigNumber((await bob.getBalance(provider)).toString());
Expand Down Expand Up @@ -100,8 +100,8 @@ describe("test transaction", function () {

transactionOne.setNonce(alice.account.nonce);
await signTransaction({ transaction: transactionOne, wallet: alice });
await provider.sendTransaction(transactionOne);
await watcher.awaitCompleted(transactionOne.getHash().hex());
const hashOne = await provider.sendTransaction(transactionOne);
await watcher.awaitCompleted(hashOne);

await bob.sync(provider);
let newBalanceOfBob = new BigNumber((await bob.getBalance(provider)).toString());
Expand Down

0 comments on commit 2af7f14

Please sign in to comment.