Skip to content

Commit

Permalink
prettier:format
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcotech committed Jul 17, 2024
1 parent f884239 commit 0dc50eb
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 62 deletions.
37 changes: 25 additions & 12 deletions tests/Arithmetic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ describe('[Arithmetic]', () => {
code = await compile('Arithmetic');
blockchain = await Blockchain.create();
user1 = await blockchain.treasury('user1');
arithmeticContract = blockchain.openContract(Arithmetic.createFromConfig({ counter: 0 }, code));
arithmeticContract = blockchain.openContract(
Arithmetic.createFromConfig({ counter: 0 }, code)
);
provider = blockchain.provider(arithmeticContract.address);
deployer = await blockchain.treasury('deployer');
(provider as any).blockchain.openContract(Arithmetic.createFromConfig({ counter: 0 }, code));
(provider as any).blockchain.openContract(
Arithmetic.createFromConfig({ counter: 0 }, code)
);
});

it('[Arithmetic] deploys', async () => {
const deployResult = await arithmeticContract.sendDeploy(deployer.getSender(), toNano('0.05'));
const deployResult = await arithmeticContract.sendDeploy(
deployer.getSender(),
toNano('0.05')
);
expect(deployResult.transactions).toHaveTransaction({
from: deployer.address,
to: arithmeticContract.address,
Expand All @@ -49,7 +56,7 @@ describe('[Arithmetic]', () => {
{
increaseBy: 12,
value: toNano('0.05'),
},
}
);
expect(increaseResult.transactions).toHaveTransaction({
from: (user1 as SandboxContract<TreasuryContract>).address,
Expand All @@ -60,10 +67,13 @@ describe('[Arithmetic]', () => {
});

it('[Arithmetic] decreases', async () => {
await arithmeticContract.sendDecrease((user1 as SandboxContract<TreasuryContract>).getSender(), {
decreaseBy: 1,
value: toNano('0.05'),
});
await arithmeticContract.sendDecrease(
(user1 as SandboxContract<TreasuryContract>).getSender(),
{
decreaseBy: 1,
value: toNano('0.05'),
}
);
expect(await arithmeticContract.getCounter()).toBe(11);
});

Expand All @@ -76,10 +86,13 @@ describe('[Arithmetic]', () => {
sendMode: SendMode.PAY_GAS_SEPARATELY,
body: beginCell().storeUint(Opcodes.multiply, 32).storeUint(0, 64).storeUint(2, 32).endCell(),
}); */
await arithmeticContract.sendMultiply((user1 as SandboxContract<TreasuryContract>).getSender(), {
multiplyBy: 2,
value: toNano('0.05'),
});
await arithmeticContract.sendMultiply(
(user1 as SandboxContract<TreasuryContract>).getSender(),
{
multiplyBy: 2,
value: toNano('0.05'),
}
);
expect(await arithmeticContract.getCounter()).toBe(22);
});
});
10 changes: 8 additions & 2 deletions tests/Fibonacci.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ describe('[Fibonacci]', () => {
});

it('[Fibonacci] deploys', async () => {
const deployResult = await contract.sendDeploy(deployer.getSender(), toNano('0.05'));
const deployResult = await contract.sendDeploy(
deployer.getSender(),
toNano('0.05')
);
expect(typeof deployResult.transactions[0].now).toBe('number');
});

Expand All @@ -41,7 +44,10 @@ describe('[Fibonacci]', () => {
const n2 = await contract.getN2();
expect(n1).toBe(vals[0]);
expect(n2).toBe(vals[1]);
await contract.sendTouch((user1 as SandboxContract<TreasuryContract>).getSender(), toNano('0.05'));
await contract.sendTouch(
(user1 as SandboxContract<TreasuryContract>).getSender(),
toNano('0.05')
);
}
});
});
45 changes: 31 additions & 14 deletions tests/OneThousandTokenTransfers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,26 @@ describe('[One thousand token transfers]', () => {
user1 = await blockchain.treasury('user1');
user2 = await blockchain.treasury('user2');
user3 = await blockchain.treasury('user3');
defaultContent = jettonContentToCell({ type: 1, uri: 'https://testjetton.org/content.json' });
defaultContent = jettonContentToCell({
type: 1,
uri: 'https://testjetton.org/content.json',
});
jettonMinter = blockchain.openContract(
JettonMinter.createFromConfig(
{
admin: user1.address,
content: defaultContent,
wallet_code: jwallet_code,
},
minter_code,
),
minter_code
)
);
userWallet = async (address: Address) =>
blockchain.openContract(JettonWallet.createFromAddress(await jettonMinter.getWalletAddress(address)));
blockchain.openContract(
JettonWallet.createFromAddress(
await jettonMinter.getWalletAddress(address)
)
);

for (let i = 0; i < 1000; i += 1) {
if (Math.random() < 0.33) {
Expand All @@ -67,7 +74,10 @@ describe('[One thousand token transfers]', () => {

// implementation detail
it('[One thousand token transfers] deploys', async () => {
const deployResult = await jettonMinter.sendDeploy(user1.getSender(), toNano('100'));
const deployResult = await jettonMinter.sendDeploy(
user1.getSender(),
toNano('100')
);

expect(deployResult.transactions).toHaveTransaction({
from: user1.address,
Expand All @@ -84,7 +94,7 @@ describe('[One thousand token transfers]', () => {
user1.address,
BigInt('100000000000'),
toNano('0.05'),
toNano('1'),
toNano('1')
);
expect(await jettonMinter.getTotalSupply()).toBe(BigInt('100000000000'));
});
Expand All @@ -101,7 +111,7 @@ describe('[One thousand token transfers]', () => {
user1.address,
null,
toNano('0.05'),
null,
null
);
await user1JettonWallet.sendTransfer(
user1.getSender(),
Expand All @@ -111,10 +121,14 @@ describe('[One thousand token transfers]', () => {
user1.address,
null,
toNano('0.05'),
null,
null
);
expect(await user2JettonWallet.getJettonBalance()).toEqual(
BigInt('33000000000')
);
expect(await user3JettonWallet.getJettonBalance()).toEqual(
BigInt('33000000000')
);
expect(await user2JettonWallet.getJettonBalance()).toEqual(BigInt('33000000000'));
expect(await user3JettonWallet.getJettonBalance()).toEqual(BigInt('33000000000'));
});

it('[One thousand token transfers] do the 1.000 transfers', async () => {
Expand All @@ -123,7 +137,8 @@ describe('[One thousand token transfers]', () => {
const senderJettonWallet = await userWallet(transfer.sender.address);
const receiverJettonWallet = await userWallet(transfer.receiver.address);

const balanceReceiverBefore = await receiverJettonWallet.getJettonBalance();
const balanceReceiverBefore =
await receiverJettonWallet.getJettonBalance();

await senderJettonWallet.sendTransfer(
transfer.sender.getSender(),
Expand All @@ -133,13 +148,15 @@ describe('[One thousand token transfers]', () => {
transfer.sender.address,
null,
toNano('0.05'),
null,
null
);
expect(await await receiverJettonWallet.getJettonBalance()).toBe(
balanceReceiverBefore + transfer.value
);
expect(await await receiverJettonWallet.getJettonBalance()).toBe(balanceReceiverBefore + transfer.value);
i += 1;
if (i % 100 === 0 && process.argv.includes('--logs')) {
console.log(
`[One thousand token transfers] ok transfer no${i} ${transfer.sender.address} -> ${transfer.receiver.address} (${transfer.value})`,
`[One thousand token transfers] ok transfer no${i} ${transfer.sender.address} -> ${transfer.receiver.address} (${transfer.value})`
);
}
}
Expand Down
13 changes: 10 additions & 3 deletions tests/TenThousandsTransfers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ describe('[Ten thousands transfers]', () => {
balance is not always exact, there may be a +1 or
-1 rounding/else error
*/
const expectedBalances = [expectedBalance - 1n, expectedBalance, expectedBalance + 1n];
const expectedBalances = [
expectedBalance - 1n,
expectedBalance,
expectedBalance + 1n,
];
const balanceReceiverAfter = await transfer.receiver.getBalance();
expect(expectedBalances.includes(balanceReceiverAfter)).toBe(true);
i += 1;
if (process.argv.includes('--logs') && (i === 100 || i === 1000 || i % 1000 === 0)) {
if (
process.argv.includes('--logs') &&
(i === 100 || i === 1000 || i % 1000 === 0)
) {
console.log(
`[Ten thousands transfers] ok transfer no${i} ${transfer.sender.address} -> ${transfer.receiver.address} (${transfer.value})`,
`[Ten thousands transfers] ok transfer no${i} ${transfer.sender.address} -> ${transfer.receiver.address} (${transfer.value})`
);
}
}
Expand Down
20 changes: 16 additions & 4 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,32 @@ const testPartial = (cmp: any, match: any) => {
}
return true;
};
export const testJettonBurnNotification = (body: Cell, match: Partial<JettonBurnNotification>) => {
export const testJettonBurnNotification = (
body: Cell,
match: Partial<JettonBurnNotification>
) => {
const res = parseBurnNotification(body);
return testPartial(res, match);
};

export const testJettonTransfer = (body: Cell, match: Partial<JettonTransfer>) => {
export const testJettonTransfer = (
body: Cell,
match: Partial<JettonTransfer>
) => {
const res = parseTransfer(body);
return testPartial(res, match);
};
export const testJettonInternalTransfer = (body: Cell, match: Partial<InternalTransfer>) => {
export const testJettonInternalTransfer = (
body: Cell,
match: Partial<InternalTransfer>
) => {
const res = parseInternalTransfer(body);
return testPartial(res, match);
};
export const testJettonNotification = (body: Cell, match: Partial<JettonTransferNotification>) => {
export const testJettonNotification = (
body: Cell,
match: Partial<JettonTransferNotification>
) => {
const res = parseTransferNotification(body);
return testPartial(res, match);
};
19 changes: 14 additions & 5 deletions wrappers/Arithmetic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from '@ton/core';
import {
Address,
beginCell,
Cell,
Contract,
contractAddress,
ContractProvider,
Sender,
SendMode,
} from '@ton/core';

export type ArithmeticConfig = {
counter: number;
Expand All @@ -17,7 +26,7 @@ export const Opcodes = {
export class Arithmetic implements Contract {
constructor(
readonly address: Address,
readonly init?: { code: Cell; data: Cell },
readonly init?: { code: Cell; data: Cell }
) {}

static createFromAddress(address: Address) {
Expand Down Expand Up @@ -47,7 +56,7 @@ export class Arithmetic implements Contract {
increaseBy: number;
value: bigint;
queryID?: number;
},
}
) {
await provider.internal(via, {
value: opts.value,
Expand All @@ -68,7 +77,7 @@ export class Arithmetic implements Contract {
value: bigint;
decreaseBy: number;
queryID?: number;
},
}
) {
await provider.internal(via, {
value: opts.value,
Expand All @@ -87,7 +96,7 @@ export class Arithmetic implements Contract {
value: bigint;
multiplyBy: number;
queryID?: number;
},
}
) {
await provider.internal(via, {
value: opts.value,
Expand Down
13 changes: 11 additions & 2 deletions wrappers/Fibonacci.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, SendMode } from '@ton/core';
import {
Address,
beginCell,
Cell,
Contract,
contractAddress,
ContractProvider,
Sender,
SendMode,
} from '@ton/core';

export function counterConfigToCell(): Cell {
return beginCell().storeUint(0, 32).storeUint(0, 32).endCell();
Expand All @@ -7,7 +16,7 @@ export function counterConfigToCell(): Cell {
export class Fibonacci implements Contract {
constructor(
readonly address: Address,
readonly init?: { code: Cell; data: Cell },
readonly init?: { code: Cell; data: Cell }
) {}

static createFromAddress(address: Address) {
Expand Down
Loading

0 comments on commit 0dc50eb

Please sign in to comment.