Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
2519727
Bringing back missing imports before refactor
ericsharma Aug 9, 2022
2940384
Adding missing files and commenting out deprecated functions
ericsharma Aug 9, 2022
b677aad
GetPlaceAsa transaction generator most of the way there
ericsharma Aug 10, 2022
429f100
Added transaction generator for placeAlgo and scoping out set up step
ericsharma Aug 12, 2022
9a0c29e
✅ placeASAEscrow spec is now passing using v2
ericsharma Aug 15, 2022
1f89143
Merge pull request #233 from algodex/231-acceptance-refactor-generate…
ericsharma Aug 15, 2022
510f93c
Merge pull request #234 from algodex/226-acceptance-add-tests-for-all…
ericsharma Aug 15, 2022
bb31174
✨ Test passing for placeAlgoWithOptIn using v2
ericsharma Aug 17, 2022
2cf310b
Merge pull request #237 from algodex/235-teal-algo-escrow-place
ericsharma Aug 17, 2022
59501e1
🧹Changed incorrect optIn boolean and added timeout to utils
ericsharma Aug 17, 2022
1c290bf
✨ PlaceAlgo with no OptIn passing using v2
ericsharma Aug 17, 2022
7f84957
Merge pull request #239 from algodex/236-teal-algo-escrow-place-no-op…
ericsharma Aug 17, 2022
aca2acf
✨Cancel ASA set up and test complete
ericsharma Aug 17, 2022
c6ecb00
Merge pull request #241 from algodex/238-close-asa-escrow-order
ericsharma Aug 18, 2022
255e637
✨ Closing Order and cleanupStep for TealAsaEscrowPlace
ericsharma Aug 18, 2022
05fc5b6
Merge pull request #242 from algodex/240-clean-up-for-asa-escrow-place
ericsharma Aug 18, 2022
98c58f2
✨Added close AlgoOrder to transaction generator
ericsharma Aug 18, 2022
f02172b
✅Updated closeAlgoEscrrowOrder to v2
ericsharma Aug 18, 2022
4b31a2e
✨CleanUp for tealAlgoNoOptin
ericsharma Aug 18, 2022
fb92a1d
✨Cancelling orders and cleanup step complete for algo with optin
ericsharma Aug 18, 2022
59a8d00
Merge pull request #244 from algodex/243-cleanup-teal-algo-escrow-place
ericsharma Aug 18, 2022
0f3c4af
✅Passing tests for asaPartialExecutiuon no optin
ericsharma Aug 19, 2022
e9c99b3
Merge pull request #246 from algodex/245-teal-asa-escrow-pay-partial-…
ericsharma Aug 19, 2022
63487cb
✨Cleanup step for partial execution no optin
ericsharma Aug 19, 2022
aaf1024
Merge pull request #248 from algodex/247-account-teardown-for-asa-esc…
ericsharma Aug 19, 2022
dab45eb
Merge branch 'main' into 249-teal-asa-escrow-pay-partial-with-opt-in
ericsharma Aug 29, 2022
77b4215
Merge branch 'development' into 249-teal-asa-escrow-pay-partial-with-…
ericsharma Aug 31, 2022
981f5a9
Merge branch 'development' into issue-226-✅_Acceptance_Add_tests_for_…
ericsharma Aug 31, 2022
e4f108f
Merge branch 'main' into 249-teal-asa-escrow-pay-partial-with-opt-in
ericsharma Sep 7, 2022
859d488
Merge branch 'main' into issue-226-✅_Acceptance_Add_tests_for_all_the…
ericsharma Sep 7, 2022
62d9479
Updated _sendTransaction for testing to reflect new and Improved batc…
ericsharma Sep 7, 2022
1571fb2
✅ Algo Pay Partial positive test /w cleanup complete
ericsharma Sep 7, 2022
d7f914a
Merge pull request #276 from algodex/275-teal-algo-partial-pay-no-opt-in
ericsharma Sep 7, 2022
693ec6e
🧹 Clean up for algo Orders
ericsharma Sep 7, 2022
8c51566
✅ Algo Pay with closeout test
ericsharma Sep 7, 2022
cb1fd9b
Merge pull request #278 from algodex/277-teal-algo-pay-with-closeout
ericsharma Sep 7, 2022
6232678
Merge branch 'issue-226-✅_Acceptance_Add_tests_for_all_the_different_…
ericsharma Sep 8, 2022
910c84d
💄 Cleanup
ericsharma Sep 8, 2022
6eef6d4
🐛 updated get wallet amount to return 0 if not opted in
ericsharma Sep 8, 2022
d330d3e
✅ Teal ASA Escrow Partial with Opt In works
ericsharma Sep 8, 2022
37a89cb
Merge branch 'issue-226-✅_Acceptance_Add_tests_for_all_the_different_…
ericsharma Sep 8, 2022
eca2ccc
Merge pull request #279 from algodex/249-teal-asa-escrow-pay-partial-…
ericsharma Sep 8, 2022
810026f
⏰Tweaking time outs to avoid edge cases where orderbook doesn't updat…
ericsharma Sep 9, 2022
a6bc46a
✅Passing test for teal escrow pay with Optin closeout
ericsharma Sep 9, 2022
d5fe85e
🧹 Changed the timeouts to avoid orderbook edgecases
ericsharma Sep 12, 2022
c4a1a7c
Merge pull request #283 from algodex/280-teal-escrow-pay-closeout-wit…
ericsharma Sep 12, 2022
6c16d10
✅ Fetch orderbook and check length before structuring any taker trans…
ericsharma Sep 12, 2022
e7137cc
🧹 Cleanup and removal of unneeded timeouts
ericsharma Sep 12, 2022
21e4337
Merge pull request #285 from algodex/284-fetch-the-orderbook-and-chec…
ericsharma Sep 12, 2022
d26382e
✅ Passing test for TealAsaEscrowPayCloseoutNoOptInTxn
ericsharma Sep 12, 2022
d0d46a6
Merge pull request #287 from algodex/286-teal-escrow-pay-closeout-no-…
ericsharma Sep 12, 2022
2c886ea
🧹Cleanup
ericsharma Sep 12, 2022
0805710
✅ Tests passing for teal algo escrow cancel
ericsharma Sep 12, 2022
c1c1f8f
Merge pull request #289 from algodex/288-teal-algo-escrow-cancel
ericsharma Sep 12, 2022
8bebe34
✅: Updated the relevant set up functions to accept an encoded note
ericsharma Sep 13, 2022
a06c811
✨Positive Teal Tests now provide a note with relevant information to …
ericsharma Sep 13, 2022
030aa50
Merge pull request #291 from algodex/✨-290-edit-account-setup-functio…
ericsharma Sep 13, 2022
01f5ea0
📚 Cleaned up the naming and re ran all tests to ensure passing
ericsharma Sep 13, 2022
e8df174
📚 More naming improvements
ericsharma Sep 13, 2022
4321309
Merge pull request #293 from algodex/292-improve-documentation-and-st…
ericsharma Sep 13, 2022
829f5cb
Skipping negative test suite
ericsharma Sep 14, 2022
a8ff23f
💄 Lint fixes
ericsharma Sep 14, 2022
e994531
✨ Changed cleanup step to find the exact asset holdings of an account
ericsharma Sep 14, 2022
8cd3000
✨Added helper functions for creating and destroying assets
ericsharma Sep 14, 2022
6eaf571
✅ Refactored positive teal tests to use randomly generated assets
ericsharma Sep 14, 2022
36a5c76
Merge pull request #296 from algodex/295-randomly-generate-the-asset-…
ericsharma Sep 14, 2022
cafd57a
✅ Updated unit tests to ignore positive teal tests
ericsharma Sep 15, 2022
dd816f1
Merge branch 'main' into issue-226-✅_Acceptance_Add_tests_for_all_the…
ericsharma Oct 19, 2022
137782b
💄 Lint fix
ericsharma Oct 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/order/__tests__/DestroyAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const algosdk = require('algosdk');
const ALGOD_SERVER = 'https://node.testnet.algoexplorerapi.io';
const ALGOD_TOKEN = ''; // { 'X-API-Key': 'VELyABA1dGqGbAVktbew4oACvp0c0298gMgYtYIb' }
const ALGOD_PORT = '';

const client = new algosdk.Algodv2(
ALGOD_TOKEN,
ALGOD_SERVER,
ALGOD_PORT,
);
/**
*
* @param {object} assetCreator
* @param {string} assetId
* @return {Promise<void>}
*/
async function destroyAsset(assetCreator, assetId) {
const params = await client.getTransactionParams().do();

const dtxn = algosdk.makeAssetDestroyTxnWithSuggestedParams(
assetCreator.addr,
undefined,
assetId,
params);

const rawSignedTxn = dtxn.signTxn(assetCreator.sk);
const txn = (await client.sendRawTransaction(rawSignedTxn).do());
const confirmedTxn = await algosdk.waitForConfirmation(client, txn.txId, 4);
console.log(confirmedTxn);

console.log('asset destroyed');
}

module.exports = destroyAsset;

60 changes: 60 additions & 0 deletions lib/order/__tests__/GenerateAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const algosdk = require('algosdk');
const ALGOD_SERVER = 'https://node.testnet.algoexplorerapi.io';
const ALGOD_TOKEN = ''; // { 'X-API-Key': 'VELyABA1dGqGbAVktbew4oACvp0c0298gMgYtYIb' }
const ALGOD_PORT = '';

const client = new algosdk.Algodv2(
ALGOD_TOKEN,
ALGOD_SERVER,
ALGOD_PORT,
);
/**
*
* @param {number} length
* @return {String}
*/
function makeid(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
/**
*
* @param {object} assetCreator
* @param {number} decimals
* @return {Promise<void>}
*/
async function generateAsset(assetCreator, decimals=6) {
const params = await client.getTransactionParams().do();

const createAssetTxn = algosdk.makeAssetCreateTxnWithSuggestedParams(
assetCreator.addr,
undefined, // no note for time being
10000000, // hardCoded issuance for time being
decimals, // hardCoded decimals for time
false,
assetCreator.addr,
undefined,
assetCreator.addr,
assetCreator.addr,
makeid(7),
makeid(7),
undefined,
undefined,
params);

const rawSignedTxn = createAssetTxn.signTxn(assetCreator.sk);
const txn = (await client.sendRawTransaction(rawSignedTxn).do());
const ptx = await algosdk.waitForConfirmation(client, txn.txId, 4);
const assetId = ptx['asset-index'];

return assetId;
}

module.exports = generateAsset;

151 changes: 151 additions & 0 deletions lib/order/__tests__/GenerateTransactionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
const withPlaceAssetTxns = require('../txns/sell/withPlaceAssetTxns');
const withPlaceAlgoTxns = require('../txns/buy/withPlaceAlgoTxns');
const withCloseAssetTxns = require('../txns/close/withCloseAssetTxns');
const withCloseAlgoTxns = require('../txns/close/withCloseAlgoTxns');
const getTakerOrders = require('../structure/getTakerOrders');
const {timeout} = require('../../teal/utils');

const compile = require('../compile/compile');
const AlgodexApi = require('../../AlgodexApi');

const tesnet = {
config: {
algod: {
uri: 'https://node.testnet.algoexplorerapi.io',
token: '',
},
indexer: {
uri: 'https://algoindexer.testnet.algoexplorerapi.io',
token: '',
},
explorer: {
uri: 'https://indexer.testnet.algoexplorerapi.io',
port: '',
},
dexd: {
uri: 'https://api-testnet-public.algodex.com/algodex-backend',
token: '',
},
},
};

const algodexApi = new AlgodexApi(tesnet);

const TransactionGenerator = {
getPlaceASAEscrowOrderTxns: async function(order) {
return await withPlaceAssetTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined' ?
await algodexApi.getAppId(order) :
order.appId,
version: 6,
indexer: algodexApi.indexer,
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
}),
);
},
getPlaceAlgoEscrowOrderTxns: async function(order) {
return await withPlaceAlgoTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined' ?
await algodexApi.getAppId(order) :
order.appId,
version: 6,
indexer: algodexApi.indexer,
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
}),
);
},
getCloseASAEscrowOrderTxns: async function(order) {
return await withCloseAssetTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined' ?
await algodexApi.getAppId(order) :
order.appId,
version: 6,
indexer: algodexApi.indexer,
contract: {
creator: order.address,
},
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
}),
);
},
getCloseAlgoEscrowOrderTxns: async function(order) {
return await withCloseAlgoTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined' ?
await algodexApi.getAppId(order) :
order.appId,
version: 6,
indexer: algodexApi.indexer,
contract: {
creator: order.address,
},
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
}),
);
},
getTakerOrderTxns: async function(order) {
algodexApi.setWallet(order.wallet);

let _orderbook = await algodexApi.http.dexd.fetchAssetOrders(order.asset.id);

while (
Object.values(_orderbook).reduce((a, b) => {
return a.concat(b); // need to put inside the while statement so the expression re runs every time _orderbook changes
}, []).length === 0
) {
await timeout(4000);
_orderbook = await algodexApi.http.dexd.fetchAssetOrders(
order.asset.id,
);
}


const orderbook = algodexApi.http.dexd.mapToAllEscrowOrders({
buy: _orderbook.buyASAOrdersInEscrow,
sell: _orderbook.sellASAOrdersInEscrow,
});

return await getTakerOrders(algodexApi, {
...order,
appId:
typeof order.appId === 'undefined' ?
await algodexApi.getAppId(order) :
order.appId,
version: 6,
indexer: algodexApi.indexer,
asset: {
...order.asset,
orderbook,
},
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
});
},
};

module.exports = TransactionGenerator;
21 changes: 13 additions & 8 deletions lib/order/__tests__/Teal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
*/

/* eslint-disable */
const {test: {getRandomAccount}, transferFunds, closeAccount, deleteApplication} = require('../../teal');
const {
test: { getRandomAccount },
transferFunds,
closeAccount,
deleteApplication,
} = require('../../teal');
// const {makePlaceAlgoEscrowOrderTxns} = require('../txns');
const _beforeAll = require('./beforeAll');
const _afterAll = require('./afterAll');
// const _beforeAll = require('./accountSetup');
// const _afterAll = require('./afterAll');
// const deleteAppTest = require('./teal_tests/deleteAppTest.js');
// const placeOrderTest = require('./teal_tests/placeAlgoEscrowOrder.js');
// const executeAlgoOrderTest = require('./teal_tests/executeAlgoEscrowOrder.js');
Expand All @@ -24,16 +29,16 @@ const JEST_MINUTE_TIMEOUT = 60 * 1000;

const config = require('../../teal/test/config');

describe('ALGO ESCROW ORDER BOOK (opt in test)', () => {
describe.skip('ALGO ESCROW ORDER BOOK (opt in test)', () => {
// Create App
beforeAll(async ()=>{
beforeAll(async () => {
if (process.env.TEST_ENV === 'integration') {
await _beforeAll(config, 'buy');
}
}, JEST_MINUTE_TIMEOUT);

// Delete App
afterAll(async ()=>{
afterAll(async () => {
if (process.env.TEST_ENV === 'integration') {
await _afterAll(config);
}
Expand All @@ -45,8 +50,8 @@ describe('ALGO ESCROW ORDER BOOK (opt in test)', () => {
[config, 800000, 1.375, false, true],
// runGroupSizeWrongTest2
[config, 800000, 1.375, false, true],
].forEach((run)=>{
it('should say something', ()=>{
].forEach((run) => {
it('should say something', () => {
expect(2).toEqual(2);
});
});
Expand Down
Loading