Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nedsalk committed Oct 7, 2024
1 parent b068568 commit 3fe26c0
Showing 1 changed file with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractFactory, Provider, Wallet, bn, hexlify } from 'fuels';
import { ContractFactory, Provider, Wallet, hexlify } from 'fuels';
import { launchTestNode } from 'fuels/test-utils';

import {
Expand Down Expand Up @@ -41,31 +41,24 @@ describe('Deploying Predicates', () => {
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
const baseAssetId = provider.getBaseAssetId();

// First, we will need to instantiate the script via it's loader bytecode. This can be imported from the typegen outputs
// that were created on `fuels deploy`. Then we can use the predicate as we would normally, such as overriding the configurables.
// First, we will need to instantiate the script via it's loader bytecode.
// This can be imported from the typegen outputs that were created on `fuels deploy`.
// Then we can use the predicate as we would normally, such as overriding the configurables.
const predicate = new TypegenPredicateLoader({
data: [bn(23)],
data: [23],
provider,
configurableConstants: {
PIN: 23,
},
});

// Now, let's fund the predicate
const { waitForResult: waitForFund } = await wallet.transfer(
predicate.address,
100_000,
baseAssetId
);
await waitForFund();
const fundTx = await wallet.transfer(predicate.address, 100_000, baseAssetId);
await fundTx.waitForResult();

// Then we'll execute the transfer and validate the predicate
const { waitForResult: waitForTransfer } = await predicate.transfer(
receiver.address,
1000,
baseAssetId
);
const { gasUsed } = await waitForTransfer();
const transferTx = await predicate.transfer(receiver.address, 1000, baseAssetId);
const { gasUsed } = await transferTx.waitForResult();
// #endregion deploying-predicates

const anotherPredicate = new TypegenPredicate({
Expand All @@ -76,19 +69,15 @@ describe('Deploying Predicates', () => {
},
});

const { waitForResult: waitForAnotherFund } = await wallet.transfer(
anotherPredicate.address,
100_000
);
await waitForAnotherFund();
const anotherFundTx = await wallet.transfer(anotherPredicate.address, 100_000);
await anotherFundTx.waitForResult();

const { waitForResult: waitForAnotherTransfer } = await anotherPredicate.transfer(
receiver.address,
1000
);
const { gasUsed: anotherGasUsed } = await waitForAnotherTransfer();
const anotherTransferTx = await anotherPredicate.transfer(receiver.address, 1000);
const { gasUsed: anotherGasUsed } = await anotherTransferTx.waitForResult();

expect(recieverInitialBalance.toNumber()).toBeLessThan(recieverInitialBalance.toNumber());
expect(recieverInitialBalance.toNumber()).toBeLessThan(
(await receiver.getBalance()).toNumber()
);
expect(gasUsed.toNumber()).toBeLessThanOrEqual(anotherGasUsed.toNumber());
});
});

0 comments on commit 3fe26c0

Please sign in to comment.