Skip to content

Commit

Permalink
add coins to transferFrom call
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Aug 23, 2024
1 parent 3e5a433 commit 8a19078
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 885 deletions.
20 changes: 20 additions & 0 deletions smart-contract/assembly/__tests__/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
} from '../contracts/main';
import { Args, u256ToBytes } from '@massalabs/as-types';
import {
Address,
changeCallStack,
mockAdminContext,
mockBalance,
mockScCall,
mockTransferredCoins,
resetStorage,
Storage,
} from '@massalabs/massa-as-sdk';
import { u256 } from 'as-bignum/assembly';
import { Schedule } from '../Schedule';
import { balanceKey } from '@massalabs/sc-standards/assembly/contracts/FT/token-internals';

const contractAddress = 'AS12BqZEQ6sByhRLyEuf0YbQmcF2PsDdkNNG1akBJu9XcjZA1eT';
const admin = 'AU1mhPhXCfh8afoNnbW91bXUVAmu8wU7u8v54yNTMvY7E52KBbz3';
Expand Down Expand Up @@ -171,6 +176,13 @@ describe('async send FT', () => {
.unwrap()[0];
switchUser(contractAddress);
mockScCall([]);

// cost of creating token balance entry
const storageCost = 9600000;

mockBalance(contractAddress, storageCost);
mockTransferredCoins(storageCost);

asyncSendFT(new Args().add(schedule.spender).add(schedule.id).serialize());
const schedules = new Args(
getSchedulesBySpender(new Args().add(spender1).serialize()),
Expand All @@ -181,6 +193,14 @@ describe('async send FT', () => {
expect(schedules[0].remaining).toBe(occurrences - 1);

// seconde autonomous execution

// Set the balance entry on token contract
Storage.setOf(
new Address(tokenAddress),
balanceKey(new Address(recipient)),
u256ToBytes(schedule.amount),
);

mockScCall([]);
asyncSendFT(new Args().add(schedule.spender).add(schedule.id).serialize());
const schedules2 = new Args(
Expand Down
7 changes: 5 additions & 2 deletions smart-contract/assembly/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ export function checkAllowance(
}

export function sendFT(schedule: Schedule): void {
const coin = new TokenWrapper(new Address(schedule.tokenAddress));
coin.transferFrom(
const token = new TokenWrapper(new Address(schedule.tokenAddress));
const coins = getBalanceEntryCost(schedule.tokenAddress, schedule.recipient);

token.transferFrom(
new Address(schedule.spender),
new Address(schedule.recipient),
schedule.amount,
coins,
);
}

Expand Down
Loading

0 comments on commit 8a19078

Please sign in to comment.