From a9d52be5eff012ea4014b741c804d0dff4798f58 Mon Sep 17 00:00:00 2001 From: rolandpo Date: Wed, 15 Nov 2023 16:19:57 +0100 Subject: [PATCH] remove test/lib --- tests/lib/flipper_swap.test.js | 122 -------------------- tests/lib/generate_plugin_config.js | 81 ------------- tests/lib/swap_exact_eth_for_tokens.test.js | 80 ------------- tests/lib/test.fixture.js | 120 ------------------- tests/lib/vault_redeem_oeth.test.js | 84 -------------- tests/lib/vault_redeem_ousd.test.js | 84 -------------- tests/lib/zapper_deposit_eth.test.js | 84 -------------- 7 files changed, 655 deletions(-) delete mode 100644 tests/lib/flipper_swap.test.js delete mode 100644 tests/lib/generate_plugin_config.js delete mode 100644 tests/lib/swap_exact_eth_for_tokens.test.js delete mode 100644 tests/lib/test.fixture.js delete mode 100644 tests/lib/vault_redeem_oeth.test.js delete mode 100644 tests/lib/vault_redeem_ousd.test.js delete mode 100644 tests/lib/zapper_deposit_eth.test.js diff --git a/tests/lib/flipper_swap.test.js b/tests/lib/flipper_swap.test.js deleted file mode 100644 index 08847c38..00000000 --- a/tests/lib/flipper_swap.test.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict"; - -require("core-js/stable"); -require("regenerator-runtime/runtime"); -var _test = require("./test.fixture"); -var _ethers = require("ethers"); -var _utils = require("ethers/lib/utils"); -// EDIT THIS: Replace with your contract address -const contractAddr = "0xcecad69d7d4ed6d52efcfa028af8732f27e08f70"; -// EDIT THIS: Replace `boilerplate` with your plugin name -const pluginName = "origin"; -const testNetwork = "ethereum"; -const abi_path = `../networks/${testNetwork}/${pluginName}/abis/` + contractAddr + '.json'; -const abi = require(abi_path); - -// Test from replayed transaction: https://etherscan.io/tx/0x1b0b3562c495b29a451b3e42d20030d30f61ce4ef56348d88f2c3b19667a1282 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Buy OUSD with USDT', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x1b0b3562c495b29a451b3e42d20030d30f61ce4ef56348d88f2c3b19667a1282 - const serializedTx = (0, _test.txFromEtherscan)("0xf889258511055921f68301496b94cecad69d7d4ed6d52efcfa028af8732f27e08f7080a435aa0b960000000000000000000000000000000000000000000000056bc75e2d6310000025a09d4c3d452778c008292e774ad9f7f8a091d951a5756a2f6f62134748a953971ca0547d2ec5ddad51cc8bdbade3abb3572b79bd83cedb7c8ef82663800fb0f2ca87"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_flipper_buy_ousd_with_usdt', [right_clicks, 0]); - await tx; - })); -}); - -// Test from replayed transaction: https://etherscan.io/tx/0x27d352b8190ffe63f2bbff5ba6f3dfc89bad4c54465821ddf486581eb3278781 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Sell OUSD for USDT', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x27d352b8190ffe63f2bbff5ba6f3dfc89bad4c54465821ddf486581eb3278781 - const serializedTx = (0, _test.txFromEtherscan)("0x02f89001208405f5e100850da2cbd3a883019ad994cecad69d7d4ed6d52efcfa028af8732f27e08f7080a4cb93905300000000000000000000000000000000000000000000000daee85907715539e9c080a0774a0c9977a4318105f6e79d983e2a0315b8fae907b58cdd3229c95341ed5d8fa015a5cbe4538fe38c54af3ff16bb914db406f2b3c3fce8f7cf58e43063b335ac0"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 11 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_flipper_sell_ousd_for_usdt', [right_clicks, 0]); - await tx; - })); -}); - -// Test from replayed transaction: https://etherscan.io/tx/0x45e0f295640eba21daefa11a0a9ae69bd0c2ea3c853906a2d80838ea0242bca5 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Buy OUSD with DAI', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x45e0f295640eba21daefa11a0a9ae69bd0c2ea3c853906a2d80838ea0242bca5 - const serializedTx = (0, _test.txFromEtherscan)("0x02f89001358412b01087850cd827cd1f83016b9994cecad69d7d4ed6d52efcfa028af8732f27e08f7080a45981c7460000000000000000000000000000000000000000000000001782ec079e566c4bc080a0335e2a61e69dc4a46fd08c75a221b094782463827f2a63a104de9b4cc77920eaa008f4e9833801a6d5eb9604afe035c57c3df3af27c1d0dae66e00e0f746d908f5"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 11 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_flipper_buy_ousd_with_dai', [right_clicks, 0]); - await tx; - })); -}); - -// Test from replayed transaction: https://etherscan.io/tx/0x4df6a5388136aa495cebb541eac214b1c9cf49b52560cd728561394ead47e369 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Sell OUSD for DAI', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x4df6a5388136aa495cebb541eac214b1c9cf49b52560cd728561394ead47e369 - const serializedTx = (0, _test.txFromEtherscan)("0x02f89001378408fcf59f850b0679b26f830176fc94cecad69d7d4ed6d52efcfa028af8732f27e08f7080a48a095a0f00000000000000000000000000000000000000000000000009a2347c0ef4f000c001a054609f2ac554219ded75cedad0fb175028f04d783b67482f91cc96a1de520250a031187dcadcc3f303fd0e3a3cdf0ee3278a211451a5695cf6183a262e3318736a"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_flipper_sell_ousd_for_dai', [right_clicks, 0]); - await tx; - })); -}); - -// Test from replayed transaction: https://etherscan.io/tx/0xfca99ebcb1efd8cd8c2cbf89f6eca2771c8d611a47ab81ea7b7f8839b0660225 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Buy OUSD with USDC', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0xfca99ebcb1efd8cd8c2cbf89f6eca2771c8d611a47ab81ea7b7f8839b0660225 - const serializedTx = (0, _test.txFromEtherscan)("0x02f8900150843b9aca00851010b872008301afb894cecad69d7d4ed6d52efcfa028af8732f27e08f7080a4bfc11ffd0000000000000000000000000000000000000000000000056bc75e2d63100000c001a05be74a21aeef60f01b923d2dc694b7a3aae42dbfb009e822a4e3c702c2928af4a06e56e3b527cfbe3bb8437aa6d6901aba48e5ac1acf0c524cf80fa820c3f87717"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 5 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_flipper_buy_ousd_with_usdc', [right_clicks, 0]); - await tx; - })); -}); - -// Test from replayed transaction: https://etherscan.io/tx/0x16aa058002f6001e2c8229f739dd85455a56411edbcc52ab1775fbbea377fafd -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Sell OUSD for USDC', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x16aa058002f6001e2c8229f739dd85455a56411edbcc52ab1775fbbea377fafd - const serializedTx = (0, _test.txFromEtherscan)("0x02f8910181f48405f5e100850eed2fed8f8301accc94cecad69d7d4ed6d52efcfa028af8732f27e08f7080a4c6b68169000000000000000000000000000000000000000000000002c3c465ca58ec0000c001a07a97565e093a20ad83b55e3cf52ffa17440c6c5a9660ad0bb9fd8cfb0401dacfa06768cb69e769a6b1cd8563f12be734c3c2aa097c1a6d8bebb058ff5399a0a711"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_flipper_sell_ousd_for_usdc', [right_clicks, 0]); - await tx; - })); -}); \ No newline at end of file diff --git a/tests/lib/generate_plugin_config.js b/tests/lib/generate_plugin_config.js deleted file mode 100644 index faae9bba..00000000 --- a/tests/lib/generate_plugin_config.js +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; - -// You will need to create a folder with this name, and put in the abis of your contracts in `abis/`. -// You will also need to create a `b2c.json` file that will hold the methodIDs and location of -// the erc20 tokens that should get displayed. -// EDIT THIS: replace with the name of your plugin (lowercase) -const pluginFolder = "origin"; -function serialize_data(pluginName, contractAddress, selector) { - const len = Buffer.from([pluginName.length]); - const name = Buffer.from(pluginName); - const address = Buffer.from(contractAddress.slice(2), "hex"); - const methodid = Buffer.from(selector.slice(2), "hex"); - - // Taking .slice(2) to remove the "0x" prefix - return Buffer.concat([len, name, address, methodid]); -} -function assert(condition, message) { - if (!condition) { - throw message || "Assertion failed"; - } -} - -// Function to generate the plugin configuration. -function generate_plugin_config(network = "ethereum") { - var fs = require('fs'); - var files = fs.readdirSync(`networks/${network}/${pluginFolder}/abis/`); - - // `contracts_to_abis` holds a maping of contract addresses to abis - let contracts_to_abis = {}; - for (let abiFileName of files) { - assert(abiFileName.toLocaleLowerCase() == abiFileName, `FAILED: File ${abiFileName} should be lower case.`); - - // Strip ".json" suffix - let contractAddress = abiFileName.slice(0, abiFileName.length - ".json".length); - // Load abi - let abi = require(`../networks/${network}/${pluginFolder}/abis/${abiFileName}`); - // Add it to contracts - contracts_to_abis[contractAddress] = abi; - } - - // Load the b2c.json file - const b2c = require(`../networks/${network}/${pluginFolder}/b2c.json`); - let res = {}; - - // Place holder signature - const PLACE_HOLDER_SIGNATURE = "3045022100f6e1a922c745e244fa3ed9a865491672808ef93f492ee0410861d748c5de201f0220160d6522499f3a84fa3e744b3b81e49e129e997b28495e58671a1169b16fa777"; - - // Iterate through contracts in b2c.json file - for (let contract of b2c["contracts"]) { - let methods_info = {}; - const contractAddress = contract["address"]; - assert(contractAddress.toLowerCase() == contractAddress, `FAILED: Contract Address ${contractAddress} should be lower case`); - for (let [selector, values] of Object.entries(contract["selectors"])) { - assert(selector.toLowerCase() == selector, `FAILED: Selector ${selector} should be lower case`); - - // Gather up the info needed for the end result - const pluginName = values["plugin"]; - const serializedData = serialize_data(pluginName, contractAddress, selector); - const signature = PLACE_HOLDER_SIGNATURE; - const erc20OfInterest = values["erc20OfInterest"]; - assert(erc20OfInterest.length <= 2, `Maximum of 2 erc20OfInterest allowed. Got ${erc20OfInterest.length}`); - - // Put them in `methods_info` - methods_info[selector] = { - "erc20OfInterest": values["erc20OfInterest"], - "plugin": pluginName, - "serialized_data": serializedData, - "signature": signature - }; - } - // Add the abi to methods_info - methods_info["abi"] = contracts_to_abis[contractAddress]; - // Add the methods_info to the end result - res[contractAddress] = methods_info; - } - assert(res.length == contracts_to_abis.length, `FAILED: ${res.length} contracts in b2c.json and ${contracts_to_abis.length} contracts in abis/ folder`); - return res; -} -module.exports = { - generate_plugin_config -}; \ No newline at end of file diff --git a/tests/lib/swap_exact_eth_for_tokens.test.js b/tests/lib/swap_exact_eth_for_tokens.test.js deleted file mode 100644 index 4b9e3e7e..00000000 --- a/tests/lib/swap_exact_eth_for_tokens.test.js +++ /dev/null @@ -1,80 +0,0 @@ -"use strict"; - -require("core-js/stable"); -require("regenerator-runtime/runtime"); -var _test = require("./test.fixture"); -var _ethers = require("ethers"); -var _utils = require("ethers/lib/utils"); -// EDIT THIS: Replace with your contract address -const contractAddr = "0x7a250d5630b4cf539739df2c5dacb4c659f2488d"; -// EDIT THIS: Replace `boilerplate` with your plugin name -const pluginName = "origin"; -const testNetwork = "ethereum"; -const abi_path = `../networks/${testNetwork}/${pluginName}/abis/` + contractAddr + '.json'; -const abi = require(abi_path); - -// Test from replayed transaction: https://etherscan.io/tx/0x0160b3aec12fd08e6be0040616c7c38248efb4413168a3372fc4d2db0e5961bb -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(20000); - test('[Nano ' + model.letter + '] Swap Exact Eth For Tokens with beneficiary', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0xb27a69cd3190ad0712da39f6b809ecc019ecbc319d3c17169853270226d18a8a - const serializedTx = (0, _test.txFromEtherscan)("0x02f9015a0181d38459682f0085215d7c1e598302a4e9947a250d5630b4cf539739df2c5dacb4c659f2488d88016345785d8a0000b8e47ff36ab50000000000000000000000000000000000000000000000018b1dd9dc51b5a9f7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000015557c8b7246c38ee71ea6dc69e4347f5dac210400000000000000000000000000000000000000000000000000000000615336100000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe2c001a089c5ce4ce199f7d93ea1d54c08133fab9407d8de63a9885d59d8ce69a59573dda045f6a0e0d3288dfdfddc23ad0afb9577c4011801f598d581a46cd0b0e2bd0571"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 12 : 6; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_swap_exact_eth_for_tokens_with_beneficiary', [right_clicks, 0]); - await tx; - })); -}); - -// Test from constructed transaction -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(20000); - test('[Nano ' + model.letter + '] Swap Exact Eth For Tokens', (0, _test.zemu)(model, async (sim, eth) => { - const contract = new _ethers.ethers.Contract(contractAddr, abi); - - // Constants used to create the transaction - // EDIT THIS: Remove what you don't need - const amountOutMin = (0, _utils.parseUnits)("28471151959593036279", 'wei'); - const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; - const SUSHI = "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2"; - const path = [WETH, SUSHI]; - const deadline = Number(1632843280); - // We set beneficiary to the default address of the emulator, so it maches sender address - const beneficiary = _test.SPECULOS_ADDRESS; - - // EDIT THIS: adapt the signature to your method - // signature: swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) - // EDIT THIS: don't call `swapExactETHForTokens` but your own method and adapt the arguments. - const { - data - } = await contract.populateTransaction.swapExactETHForTokens(amountOutMin, path, beneficiary, deadline); - - // Get the generic transaction template - let unsignedTx = _test.genericTx; - // Modify `to` to make it interact with the contract - unsignedTx.to = contractAddr; - // Modify the attached data - unsignedTx.data = data; - // EDIT THIS: get rid of this if you don't wish to modify the `value` field. - // Modify the number of ETH sent - unsignedTx.value = (0, _utils.parseEther)("0.1"); - - // Create serializedTx and remove the "0x" prefix - const serializedTx = _ethers.ethers.utils.serializeTransaction(unsignedTx).slice(2); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button 10 times, then pressing both buttons to accept the transaction. - // EDIT THIS: modify `10` to fix the number of screens you are expecting to navigate through. - await sim.navigateAndCompareSnapshots('.', model.name + '_swap_exact_eth_for_tokens', [right_clicks, 0]); - await tx; - })); -}); \ No newline at end of file diff --git a/tests/lib/test.fixture.js b/tests/lib/test.fixture.js deleted file mode 100644 index 3485515e..00000000 --- a/tests/lib/test.fixture.js +++ /dev/null @@ -1,120 +0,0 @@ -"use strict"; - -var _zemu = _interopRequireWildcard(require("@zondax/zemu")); -var _hwAppEth = _interopRequireDefault(require("@ledgerhq/hw-app-eth")); -var _generate_plugin_config = require("./generate_plugin_config"); -var _utils = require("ethers/lib/utils"); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } -function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } -const transactionUploadDelay = 60000; -async function waitForAppScreen(sim) { - await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot(), transactionUploadDelay); -} -const sim_options_nano = { - ..._zemu.DEFAULT_START_OPTIONS, - logging: true, - X11: true, - startDelay: 5000, - startText: 'is ready' -}; -const Resolve = require('path').resolve; -const NANOS_ETH_PATH = Resolve('elfs/ethereum_nanos.elf'); -const NANOSP_ETH_PATH = Resolve('elfs/ethereum_nanosp.elf'); -const NANOX_ETH_PATH = Resolve('elfs/ethereum_nanox.elf'); -const NANOS_PLUGIN_PATH = Resolve('elfs/plugin_nanos.elf'); -const NANOSP_PLUGIN_PATH = Resolve('elfs/plugin_nanosp.elf'); -const NANOX_PLUGIN_PATH = Resolve('elfs/plugin_nanox.elf'); -const nano_models = [{ - name: 'nanos', - letter: 'S', - path: NANOS_PLUGIN_PATH, - eth_path: NANOS_ETH_PATH -}, { - name: 'nanosp', - letter: 'SP', - path: NANOSP_PLUGIN_PATH, - eth_path: NANOSP_ETH_PATH -}, { - name: 'nanox', - letter: 'X', - path: NANOX_PLUGIN_PATH, - eth_path: NANOX_ETH_PATH -}]; -const originJSON = (0, _generate_plugin_config.generate_plugin_config)(); -const SPECULOS_ADDRESS = '0xFE984369CE3919AA7BB4F431082D027B4F8ED70C'; -const RANDOM_ADDRESS = '0xaaaabbbbccccddddeeeeffffgggghhhhiiiijjjj'; -let genericTx = { - nonce: Number(0), - gasLimit: Number(21000), - gasPrice: (0, _utils.parseUnits)('1', 'gwei'), - value: (0, _utils.parseEther)('1'), - chainId: 1, - to: RANDOM_ADDRESS, - data: null -}; -const TIMEOUT = 1000000; - -// Generates a serializedTransaction from a rawHexTransaction copy pasted from etherscan. -function txFromEtherscan(rawTx) { - // Remove 0x prefix - rawTx = rawTx.slice(2); - let txType = rawTx.slice(0, 2); - if (txType == "02" || txType == "01") { - // Remove "02" prefix - rawTx = rawTx.slice(2); - } else { - txType = ""; - } - let decoded = _utils.RLP.decode("0x" + rawTx); - if (txType != "") { - decoded = decoded.slice(0, decoded.length - 3); // remove v, r, s - } else { - decoded[decoded.length - 1] = "0x"; // empty - decoded[decoded.length - 2] = "0x"; // empty - decoded[decoded.length - 3] = "0x01"; // chainID 1 - } - - // Encode back the data, drop the '0x' prefix - let encoded = _utils.RLP.encode(decoded).slice(2); - - // Don't forget to prepend the txtype - return txType + encoded; -} -function zemu(device, func) { - return async () => { - jest.setTimeout(TIMEOUT); - let elf_path; - let lib_elf; - elf_path = device.eth_path; - // Edit this: replace `Boilerplate` by your plugin name - lib_elf = { - 'origin': device.path - }; - const sim = new _zemu.default(elf_path, lib_elf); - try { - await sim.start({ - ...sim_options_nano, - model: device.name - }); - const transport = await sim.getTransport(); - const eth = new _hwAppEth.default(transport); - eth.setLoadConfig({ - baseURL: null, - extraPlugins: originJSON - }); - await func(sim, eth); - } finally { - await sim.close(); - } - }; -} -module.exports = { - zemu, - waitForAppScreen, - genericTx, - nano_models, - SPECULOS_ADDRESS, - RANDOM_ADDRESS, - txFromEtherscan -}; \ No newline at end of file diff --git a/tests/lib/vault_redeem_oeth.test.js b/tests/lib/vault_redeem_oeth.test.js deleted file mode 100644 index 7a156f8d..00000000 --- a/tests/lib/vault_redeem_oeth.test.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; - -require("core-js/stable"); -require("regenerator-runtime/runtime"); -var _test = require("./test.fixture"); -var _ethers = require("ethers"); -var _utils = require("ethers/lib/utils"); -// EDIT THIS: Replace with your contract address -const contractAddr = "0x39254033945aa2e4809cc2977e7087bee48bd7ab"; -// EDIT THIS: Replace `boilerplate` with your plugin name -const pluginName = "origin"; -const testNetwork = "ethereum"; -const abi_path = `../networks/${testNetwork}/${pluginName}/abis/` + contractAddr + '.json'; -const abi = require(abi_path); - -// Test from replayed transaction: https://etherscan.io/tx/0x24587806cb75a6159e4d8329289a6c140ba12ecee8934586d4d3452932271ce7 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Redeem OETH', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x24587806cb75a6159e4d8329289a6c140ba12ecee8934586d4d3452932271ce7 - const serializedTx = (0, _test.txFromEtherscan)("0x02f8b1015c8405f5e1008509f8630ef48308d7289439254033945aa2e4809cc2977e7087bee48bd7ab80b8447cbc237300000000000000000000000000000000000000000000000009d2d4b74c9da3c500000000000000000000000000000000000000000000000009b6e64a8ec60000c080a0617e25a8c320e4bce9321cb9d731bd934c6beeed226e49c50651dcd57599e3eca060b6ec97000e85dfd54de86c224131e51ab47026b5bf0ab044631f16e36f7240"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 9 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_vault_redeem_oeth', [right_clicks, 0]); - await tx; - })); -}); - -// Test from constructed transaction -// EDIT THIS: build your own test -/*nano_models.forEach(function(model) { - jest.setTimeout(20000) - test('[Nano ' + model.letter + '] Swap Exact Eth For Tokens', zemu(model, async (sim, eth) => { - const contract = new ethers.Contract(contractAddr, abi); - - // Constants used to create the transaction - // EDIT THIS: Remove what you don't need - const amountOutMin = parseUnits("28471151959593036279", 'wei'); - const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; - const SUSHI = "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2"; - const path = [WETH, SUSHI]; - const deadline = Number(1632843280); - // We set beneficiary to the default address of the emulator, so it maches sender address - const beneficiary = SPECULOS_ADDRESS; - - // EDIT THIS: adapt the signature to your method - // signature: swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) - // EDIT THIS: don't call `swapExactETHForTokens` but your own method and adapt the arguments. - const {data} = await contract.populateTransaction.swapExactETHForTokens(amountOutMin, path, beneficiary ,deadline); - - // Get the generic transaction template - let unsignedTx = genericTx; - // Modify `to` to make it interact with the contract - unsignedTx.to = contractAddr; - // Modify the attached data - unsignedTx.data = data; - // EDIT THIS: get rid of this if you don't wish to modify the `value` field. - // Modify the number of ETH sent - unsignedTx.value = parseEther("0.1"); - - // Create serializedTx and remove the "0x" prefix - const serializedTx = ethers.utils.serializeTransaction(unsignedTx).slice(2); - - const tx = eth.signTransaction( - "44'/60'/0'/0", - serializedTx - ); - - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await waitForAppScreen(sim); - // Navigate the display by pressing the right button 10 times, then pressing both buttons to accept the transaction. - // EDIT THIS: modify `10` to fix the number of screens you are expecting to navigate through. - await sim.navigateAndCompareSnapshots('.', model.name + '_swap_exact_eth_for_tokens', [right_clicks, 0]); - - await tx; - })); -});*/ \ No newline at end of file diff --git a/tests/lib/vault_redeem_ousd.test.js b/tests/lib/vault_redeem_ousd.test.js deleted file mode 100644 index 35213543..00000000 --- a/tests/lib/vault_redeem_ousd.test.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; - -require("core-js/stable"); -require("regenerator-runtime/runtime"); -var _test = require("./test.fixture"); -var _ethers = require("ethers"); -var _utils = require("ethers/lib/utils"); -// EDIT THIS: Replace with your contract address -const contractAddr = "0xe75d77b1865ae93c7eaa3040b038d7aa7bc02f70"; -// EDIT THIS: Replace `boilerplate` with your plugin name -const pluginName = "origin"; -const testNetwork = "ethereum"; -const abi_path = `../networks/${testNetwork}/${pluginName}/abis/` + contractAddr + '.json'; -const abi = require(abi_path); - -// Test from replayed transaction: https://etherscan.io/tx/0xfbb0557cc85b244a68a1bf030379c43117723375326e44c43db44af54a31ece0 -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(100000); - test('[Nano ' + model.letter + '] Redeem OUSD', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0xfbb0557cc85b244a68a1bf030379c43117723375326e44c43db44af54a31ece0 - const serializedTx = (0, _test.txFromEtherscan)("0xf8aa0485055ae826008328155794e75d77b1865ae93c7eaa3040b038d7aa7bc02f7080b8447cbc2373000000000000000000000000000000000000000000003ea6080a7f4ba08e59ff000000000000000000000000000000000000000000003e2a03f3da153c51000025a0e98bbec6aa4ed8480923d5c5b74dcadf09d0bcd6b1c794500da9e5f12b32def3a069f50d96250a062339968570da2233676acc9886286a1f2ead8d5909efbe284b"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_vault_redeem_ousd', [right_clicks, 0]); - await tx; - })); -}); - -// Test from constructed transaction -// EDIT THIS: build your own test -/*nano_models.forEach(function(model) { - jest.setTimeout(20000) - test('[Nano ' + model.letter + '] Swap Exact Eth For Tokens', zemu(model, async (sim, eth) => { - const contract = new ethers.Contract(contractAddr, abi); - - // Constants used to create the transaction - // EDIT THIS: Remove what you don't need - const amountOutMin = parseUnits("28471151959593036279", 'wei'); - const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; - const SUSHI = "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2"; - const path = [WETH, SUSHI]; - const deadline = Number(1632843280); - // We set beneficiary to the default address of the emulator, so it maches sender address - const beneficiary = SPECULOS_ADDRESS; - - // EDIT THIS: adapt the signature to your method - // signature: swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) - // EDIT THIS: don't call `swapExactETHForTokens` but your own method and adapt the arguments. - const {data} = await contract.populateTransaction.swapExactETHForTokens(amountOutMin, path, beneficiary ,deadline); - - // Get the generic transaction template - let unsignedTx = genericTx; - // Modify `to` to make it interact with the contract - unsignedTx.to = contractAddr; - // Modify the attached data - unsignedTx.data = data; - // EDIT THIS: get rid of this if you don't wish to modify the `value` field. - // Modify the number of ETH sent - unsignedTx.value = parseEther("0.1"); - - // Create serializedTx and remove the "0x" prefix - const serializedTx = ethers.utils.serializeTransaction(unsignedTx).slice(2); - - const tx = eth.signTransaction( - "44'/60'/0'/0", - serializedTx - ); - - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await waitForAppScreen(sim); - // Navigate the display by pressing the right button 10 times, then pressing both buttons to accept the transaction. - // EDIT THIS: modify `10` to fix the number of screens you are expecting to navigate through. - await sim.navigateAndCompareSnapshots('.', model.name + '_swap_exact_eth_for_tokens', [right_clicks, 0]); - - await tx; - })); -});*/ \ No newline at end of file diff --git a/tests/lib/zapper_deposit_eth.test.js b/tests/lib/zapper_deposit_eth.test.js deleted file mode 100644 index 3ee933f6..00000000 --- a/tests/lib/zapper_deposit_eth.test.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; - -require("core-js/stable"); -require("regenerator-runtime/runtime"); -var _test = require("./test.fixture"); -var _ethers = require("ethers"); -var _utils = require("ethers/lib/utils"); -// EDIT THIS: Replace with your contract address -const contractAddr = "0x9858e47bcbbe6fbac040519b02d7cd4b2c470c66"; -// EDIT THIS: Replace `boilerplate` with your plugin name -const pluginName = "origin"; -const testNetwork = "ethereum"; -const abi_path = `../networks/${testNetwork}/${pluginName}/abis/` + contractAddr + '.json'; -const abi = require(abi_path); - -// Test from replayed transaction: https://etherscan.io/tx/0x0160b3aec12fd08e6be0040616c7c38248efb4413168a3372fc4d2db0e5961bb -// EDIT THIS: build your own test -_test.nano_models.forEach(function (model) { - jest.setTimeout(20000); - test('[Nano ' + model.letter + '] Swap Exact Eth For Tokens with beneficiary', (0, _test.zemu)(model, async (sim, eth) => { - // The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0xb27a69cd3190ad0712da39f6b809ecc019ecbc319d3c17169853270226d18a8a - const serializedTx = (0, _test.txFromEtherscan)("0x02f87b01820d868405f5e100850d9ab37de38307f720949858e47bcbbe6fbac040519b02d7cd4b2c470c6689022b1c8c1227a0000084d0e30db0c080a0361d87d1d88d16d29b8e983b57510b19697b34a5648bcc6f74bf0940ce40b8eaa043f59af459e0bb7bb7e09989c9459de2a62e5feb4099a269316c7fad0be52b82"); - const tx = eth.signTransaction("44'/60'/0'/0", serializedTx); - const right_clicks = model.letter === 'S' ? 12 : 6; - - // Wait for the application to actually load and parse the transaction - await (0, _test.waitForAppScreen)(sim); - // Navigate the display by pressing the right button `right_clicks` times, then pressing both buttons to accept the transaction. - await sim.navigateAndCompareSnapshots('.', model.name + '_zapper_deposit_eth', [right_clicks, 0]); - await tx; - })); -}); - -// Test from constructed transaction -// EDIT THIS: build your own test -/*nano_models.forEach(function(model) { - jest.setTimeout(20000) - test('[Nano ' + model.letter + '] Swap Exact Eth For Tokens', zemu(model, async (sim, eth) => { - const contract = new ethers.Contract(contractAddr, abi); - - // Constants used to create the transaction - // EDIT THIS: Remove what you don't need - const amountOutMin = parseUnits("28471151959593036279", 'wei'); - const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; - const SUSHI = "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2"; - const path = [WETH, SUSHI]; - const deadline = Number(1632843280); - // We set beneficiary to the default address of the emulator, so it maches sender address - const beneficiary = SPECULOS_ADDRESS; - - // EDIT THIS: adapt the signature to your method - // signature: swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) - // EDIT THIS: don't call `swapExactETHForTokens` but your own method and adapt the arguments. - const {data} = await contract.populateTransaction.swapExactETHForTokens(amountOutMin, path, beneficiary ,deadline); - - // Get the generic transaction template - let unsignedTx = genericTx; - // Modify `to` to make it interact with the contract - unsignedTx.to = contractAddr; - // Modify the attached data - unsignedTx.data = data; - // EDIT THIS: get rid of this if you don't wish to modify the `value` field. - // Modify the number of ETH sent - unsignedTx.value = parseEther("0.1"); - - // Create serializedTx and remove the "0x" prefix - const serializedTx = ethers.utils.serializeTransaction(unsignedTx).slice(2); - - const tx = eth.signTransaction( - "44'/60'/0'/0", - serializedTx - ); - - const right_clicks = model.letter === 'S' ? 7 : 5; - - // Wait for the application to actually load and parse the transaction - await waitForAppScreen(sim); - // Navigate the display by pressing the right button 10 times, then pressing both buttons to accept the transaction. - // EDIT THIS: modify `10` to fix the number of screens you are expecting to navigate through. - await sim.navigateAndCompareSnapshots('.', model.name + '_swap_exact_eth_for_tokens', [right_clicks, 0]); - - await tx; - })); -});*/ \ No newline at end of file