Skip to content

Commit 9a0c29e

Browse files
committed
✅ placeASAEscrow spec is now passing using v2
1 parent 429f100 commit 9a0c29e

File tree

7 files changed

+86
-48
lines changed

7 files changed

+86
-48
lines changed

lib/order/__tests__/GenerateTransactionTypes.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const makePlaceAssetTxns = require('../txns/sell/makePlaceAssetTxns');
1+
const withPlaceAssetTxns = require('../txns/sell/withPlaceAssetTxns');
22
const makePlaceAlgoTxns = require('../txns/buy/makePlaceAlgoTxns');
33
const compile = require('../compile/compile');
44
const AlgodexApi = require('../../AlgodexApi');
@@ -28,10 +28,7 @@ const algodexApi = new AlgodexApi(tesnet);
2828

2929
const TransactionGenerator = {
3030
getPlaceASAEscrowOrderTxns: async function (order, optIn) {
31-
const newWallet = await algodexApi.http.indexer.fetchAccountInfo(
32-
order.wallet
33-
);
34-
return await makePlaceAssetTxns(
31+
return await withPlaceAssetTxns(
3532
await compile({
3633
...order,
3734
appId:

lib/order/__tests__/TealAsaEscrowPlace.spec.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const connector = require('../../wallet/connectors/AlgoSDK');
1010
const placeASAOrderTest = require('./teal_tests/placeASAEscrowOrder.js');
1111
// const closeASAOrderTest = require('./teal_tests/closeASAEscrowOrder.js');
1212
const constants = require('./constants.js');
13-
const beforeAll = require('./beforeAll.js');
13+
const setup = require('./beforeAll.js');
1414
const JEST_MINUTE_TIMEOUT = 60 * 1000;
1515

1616
const config = {
@@ -28,7 +28,7 @@ console.log(
2828
'DEBUG_SMART_CONTRACT_SOURCE is: ' + constants.DEBUG_SMART_CONTRACT_SOURCE
2929
);
3030

31-
const textEncoder = new TextEncoder();
31+
3232
//
3333
// // TODO: The negative tests need to be implemented. The commented ones out are examples but will not work with
3434
// // this transaction type.
@@ -59,9 +59,14 @@ const textEncoder = new TextEncoder();
5959
//
6060
//
6161
describe('ASA ESCROW ORDER BOOK', () => {
62+
function timeout(ms) {
63+
return new Promise(resolve => setTimeout(resolve, ms));
64+
}
6265
beforeAll(async () => {
63-
// setup step: Send target asset from open account to creator account
64-
});
66+
await setup(config, 'sell', true)
67+
await timeout(7000) // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
68+
69+
}, JEST_MINUTE_TIMEOUT);
6570
// test(
6671
// 'Create asa escrow order book',
6772
// async () => {

lib/order/__tests__/beforeAll.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const AlgodexApi = require('../../AlgodexApi');
44
const apiConfig = require('../../../config.json');
55
const initAccounts = require('../../teal/test/initAccounts');
66
const logger = require('../../logger');
7+
8+
9+
710
/**
811
*
912
* @param {TestConfig} config Test Configuration
@@ -19,31 +22,32 @@ async function beforeAll(config, type, optIn = false, newCreator = false) {
1922
}
2023

2124
// Initalize API Client
22-
await config.init(AlgodexApi, [apiConfig]);
25+
// await config.init(AlgodexApi, [apiConfig]);
26+
const api = new AlgodexApi(apiConfig)
2327

2428
// Initialize Accounts and Configuration
2529
await initAccounts(config, optIn, newCreator);
2630

27-
const {client, creatorAccount} = config;
28-
const createTxn = await txns.makeApplicationCreateTxn(
29-
client,
30-
type,
31-
creatorAccount,
32-
config.suggestedParams,
33-
);
34-
const txId = createTxn.txID().toString();
31+
// const {client, creatorAccount} = config;
32+
// const createTxn = await txns.makeApplicationCreateTxn(
33+
// client,
34+
// type,
35+
// creatorAccount,
36+
// config.suggestedParams,
37+
// );
38+
// const txId = createTxn.txID().toString();
3539

36-
const signedTxn = createTxn.signTxn(creatorAccount.sk);
40+
// const signedTxn = createTxn.signTxn(creatorAccount.sk);
3741

38-
await client.sendRawTransaction(signedTxn).do();
42+
// await client.sendRawTransaction(signedTxn).do();
3943

40-
// Wait for confirmation
41-
await algosdk.waitForConfirmation(client, txId, 10);
44+
// // Wait for confirmation
45+
// await algosdk.waitForConfirmation(client, txId, 10);
4246

43-
// display results
44-
const transactionResponse = await client.pendingTransactionInformation(txId).do();
47+
// // display results
48+
// const transactionResponse = await client.pendingTransactionInformation(txId).do();
4549

46-
config.setAppIndex(transactionResponse['application-index']);
50+
// config.setAppIndex(transactionResponse['application-index']);
4751
}
4852

4953
module.exports = beforeAll;

lib/order/__tests__/teal_tests/placeASAEscrowOrder.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
const testHelper = require('../setup.js');
33
const transactionGenerator = require('../GenerateTransactionTypes');
44
const algosdk = require('algosdk');
5+
const signer = require('../../../wallet/signers/AlgoSDK')
6+
7+
const _sendTransactions = async (client, signedTransactions) => {
8+
for (const group of signedTransactions) {
9+
console.debug(`Sending ${group.length} Group Transactions`);
10+
const rawTxns = group.map((txn) => txn.blob);
11+
12+
const {txId} = await client.sendRawTransaction(rawTxns).do();
13+
console.debug(`Waiting for confirmation for ${txId}`);
14+
await algosdk.waitForConfirmation(client, txId, 10);
15+
console.debug(`Confirmed ${txId}`);
16+
}
17+
};
518

619
const PRINT_TXNS = 0;
720

@@ -22,7 +35,7 @@ const Test = {
2235
address: config.creatorAccount.addr,
2336
connector: {
2437
...config.connector,
25-
sk: config.creatorAccount.sk,
38+
sk: config.creatorAccount.sk, //Just in case we want to test signing and sending from the api and not from the tests.
2639
connected: true,
2740
},
2841
// mnemonic: config.creatorAccount.sk,
@@ -43,18 +56,17 @@ const Test = {
4356
wallet: wallet,
4457
};
4558

46-
const outerTxns = await transactionGenerator.getPlaceASAEscrowOrderTxns(
59+
const placeASAEscrowOrder = await transactionGenerator.getPlaceASAEscrowOrderTxns(
4760
order,
4861
optIn
4962
);
50-
debugger;
5163

5264
if (returnOuterTransactions) {
5365
return outerTxns;
5466
}
55-
const signedTxns = testHelper.groupAndSignTransactions(outerTxns);
67+
const signedTxns = await signer([placeASAEscrowOrder], config.creatorAccount.sk)
5668

57-
await testHelper.sendAndCheckConfirmed(client, signedTxns);
69+
const confirmation = await _sendTransactions(client, signedTxns);
5870

5971
return true;
6072
},

lib/order/txns/buy/makeExecuteAlgoTxns.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('makeExecuteAlgoTxns', () => {
7777
// };
7878
// }).forEach(({order, exist, optIn})=>{
7979
let signedTxns;
80-
it('should create ExecuteAlgoTxns', async () => {
80+
it.skip('should create ExecuteAlgoTxns', async () => {
8181
const openBuyOrder = (await config.api.http.dexd.fetchOrders('wallet', 'UUEUTRNQY7RUXESXRDO7HSYRSJJSSVKYVB4DI7X2HVVDWYOBWJOP5OSM3A')).filter((o) => o.type === 'buy')[0];
8282
openBuyOrder.wallet = config.api.wallet;
8383
openBuyOrder.client = config.client;

lib/teal/test/initAccounts.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@ async function initAccounts(config, optIn = false, newCreator = false) {
1515
// and overrides the current creator account
1616
config.setCreatorAccount(algosdk.generateAccount());
1717
}
18+
const {client, openAccount, maliciousAccount, creatorAccount, executorAccount, assetId} = config;
1819

19-
await transferFunds(config.client, config.openAccount, config.creatorAccount, 2000000);
2020

21-
const {client, openAccount, maliciousAccount, creatorAccount, executorAccount} = config;
21+
await transferFunds(client, openAccount, creatorAccount, 2000000);
2222

2323

24-
await transferFunds(client, openAccount, creatorAccount, 5000000); // 5 algos
25-
await transferFunds(client, openAccount, executorAccount, 5000000); // 5 algos
26-
await transferASA(client, creatorAccount, creatorAccount, 0, config.assetIndex); // opt in transaction
27-
await transferASA(client, openAccount, creatorAccount, 2000000, config.assetIndex); // 5 algos
2824

29-
if (optIn) {
30-
await transferASA(client, executorAccount, executorAccount, 0, config.assetIndex); // opt in transaction
31-
await transferASA(client, openAccount, executorAccount, 2000000, config.assetIndex); // 5 algos
32-
}
25+
// await transferFunds(client, openAccount, creatorAccount, 5000000); // 5 algos
26+
// await transferFunds(client, openAccount, executorAccount, 5000000); // 5 algos
27+
await transferASA(client, creatorAccount, creatorAccount, 0, assetId); // opt in transaction
28+
await transferASA(client, openAccount, creatorAccount, 2000000, assetId); // 5 algos
29+
30+
// if (optIn) {
31+
// await transferASA(client, executorAccount, executorAccount, 0, config.assetIndex); // opt in transaction
32+
// await transferASA(client, openAccount, executorAccount, 2000000, config.assetIndex); // 5 algos
33+
// }
3334

34-
await transferFunds(client, openAccount, maliciousAccount, 5000000); // 5 algos
35-
await transferASA(client, maliciousAccount, maliciousAccount, 0, config.assetIndex); // opt in transaction
36-
await transferASA(client, openAccount, maliciousAccount, 2000000, config.assetIndex); // 5 algos
35+
// await transferFunds(client, openAccount, maliciousAccount, 5000000); // 5 algos
36+
// await transferASA(client, maliciousAccount, maliciousAccount, 0, config.assetIndex); // opt in transaction
37+
// await transferASA(client, openAccount, maliciousAccount, 2000000, config.assetIndex); // 5 algos
3738
}
3839

3940
module.exports = initAccounts;

lib/teal/utils.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,16 @@ async function closeAccount(client, fromAccount, toAccount) {
185185
* @return {Promise<void>}
186186
*/
187187
async function transferFunds(client, fromAccount, toAccount, amount) {
188-
const fundTxn = await txns.makePaymentTxn(
189-
client, fromAccount, toAccount, amount, false,
190-
);
188+
const _suggestedParams = await client.getTransactionParams().do()
189+
const fundTxn = algosdk.makePaymentTxnWithSuggestedParams(
190+
fromAccount.addr,
191+
toAccount.addr,
192+
amount,
193+
undefined,
194+
undefined,
195+
_suggestedParams,
196+
undefined,
197+
)
191198
const fundTxnId = fundTxn.txID().toString();
192199

193200
const signedFundTxn = fundTxn.signTxn(fromAccount.sk);
@@ -279,7 +286,19 @@ async function transferASA(
279286
amount,
280287
assetId,
281288
) {
282-
const asaTransferTxn = await txns.makeAssetTransferTxn(client, fromAccount, toAccount, amount, assetId, false);
289+
const _suggestedParams = await client.getTransactionParams().do()
290+
291+
const asaTransferTxn = algosdk.makeAssetTransferTxnWithSuggestedParams(
292+
fromAccount.addr,
293+
toAccount.addr,
294+
undefined,
295+
undefined,
296+
amount,
297+
undefined,
298+
assetId,
299+
_suggestedParams,
300+
undefined,
301+
)
283302
const asaTxnId = asaTransferTxn.txID().toString();
284303

285304
const signedFundTxn = asaTransferTxn.signTxn(fromAccount.sk);

0 commit comments

Comments
 (0)