Best JavaScript code snippet using wpt
dex_market_order_test.js
Source:dex_market_order_test.js
...7contract("Dex-market-order", accounts=>{8 //To create a SELL market order, the user must have token deposited such that deposited token >= sell order amount"9 it("Should throw an error when creating a sell market order without adequate token balance", async()=>{10 let dex = await Dex.deployed()11 let balance = await dex.getBalance(accounts[0], web3.utils.fromUtf8("LINK"))12 //console.log(balance.toNumber())13 assert.equal(balance.toNumber(),0, "Initial balance is not zero")14 await truffleAssert.reverts(15 dex.createMarketOrder(1, web3.utils.fromUtf8("LINK"),10)16 ) 17 })18 19 it("BUY orders can be submited even when BUY order book is empty", async()=>{20 let dex = await Dex.deployed()21 await dex.depositEth({value: 10000})22 let buyBook = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 0) // get buy side orderbook23 assert.equal(buyBook.length, 0, "Buy book is not empty")24 await truffleAssert.passes(25 dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),20)26 ) 27 })28 //If there is enough liquidity in the order book, market sell orders should be filled until the market order is 100% filled29 it("Market orders should not be filled more limit orders than matket orders", async()=>{30 let dex = await Dex.deployed()31 let link = await Link.deployed()32 let sellBook = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1) // get sell side orderbook33 assert.equal(sellBook.length, 0, "sell book is not empty initailly")34 dex.addToken(web3.utils.fromUtf8("LINK"), link.address)35 //transfer from accounst[0] to accounts[1],accounts[2],accounts[3] 36 await link.transfer(accounts[1],500)37 await link.transfer(accounts[2],500)38 await link.transfer(accounts[3],500)39 //approve DEX for accounts[1],accounts[2],accounts[3]40 await link.approve(dex.address, 150, {from:accounts[1]}) 41 await link.approve(dex.address, 150, {from:accounts[2]})42 await link.approve(dex.address, 150, {from:accounts[3]})43 //Deposit DEX to accounts[1],accounts[2],accounts[3]44 await dex.deposit(50, web3.utils.fromUtf8("LINK"), {from:accounts[1]})45 await dex.deposit(50, web3.utils.fromUtf8("LINK"), {from:accounts[2]})46 await dex.deposit(50, web3.utils.fromUtf8("LINK"), {from:accounts[3]})47 //fill up the sell order48 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),5,300,{from:accounts[1]})49 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),5,400,{from:accounts[2]})50 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),5,500,{from:accounts[3]})51 52 //create a market order that should fill up 2/3 orders in the book53 await dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),10)54 //get sell order book55 sellBook = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1)56 57 assert(sellBook.length==1, "Sell book should only have one order left")58 assert(sellBook[0].filled == 0, "Sell side should have 0 filled")59 })60 //If there is enough liquidity in the order book, market sell orders should be filled until the market order is 100% filled61 it("Market orders should be 100% filled untill the order book is empty", async()=>{62 let dex = await Dex.deployed()63 let link = await Link.deployed()64 let sellBook = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1)65 assert(sellBook.length==1, "should only have one order left from the previous test")66 //fill up the order book again67 await link.approve(dex.address, 500, { from: accounts[1] })68 await link.approve(dex.address, 500, { from: accounts[2] })69 await dex.deposit(100, web3.utils.fromUtf8("LINK"), {from: accounts[1] })70 await dex.deposit(100, web3.utils.fromUtf8("LINK"), {from:accounts[2]})71 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),5,300,{from:accounts[1]})72 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),5,400,{from:accounts[2]})73 //check buyer link balance before link purchase74 let balanceBefore = await dex.getBalance(accounts[0], web3.utils.fromUtf8("LINK"));75 //create a market buy order that ask for more than the entire market sell book (15 LINK)76 await dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),50)77 //check buyer link balance after link purchase78 let balanceAfter = await dex.getBalance(accounts[0], web3.utils.fromUtf8("LINK"));79 //buyer should have 15 more LINK after purchase even the buy order specified 50 LINK80 assert.equal(balanceBefore.toNumber()+15,balanceAfter.toNumber())81 })82 it("The ETH balance of the buyer should decrease with the filled amounts.", async()=>{83 let dex = await Dex.deployed()84 let link = await Link.deployed()85 //seller (accounts[1]) deposit link and sell it for 300 wei (limit order)86 await link.approve(dex.address, 500, { from: accounts[1] })87 88 await dex.deposit(100, web3.utils.fromUtf8("LINK"), {from:accounts[1]})89 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),1,300, {from:accounts[1]})90 //check buyer ETH balance before trade91 let balanceBefore = await dex.getBalance(accounts[0], web3.utils.fromUtf8("ETH"));92 await dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),1)93 let balanceAfter = await dex.getBalance(accounts[0], web3.utils.fromUtf8("ETH"));94 //buyer should have 300 less ETH after purchase 95 assert.equal(balanceBefore.toNumber()-300,balanceAfter.toNumber())96 })97 xit("The token balance(s) of the token sell(s) should decrease with the filled amounts.", async()=>{98 let dex = await Dex.deployed()99 let link = await Link.deployed()100 101 let sellBook = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1) // get sell side orderbook102 assert(sellBook.length == 0, "sell book is not empty initailly")103 104 105 //seller account[2] approve and deposit LINK106 await link.approve(dex.address, 500, {from:accounts[2]})107 await dex.deposit(100, web3.utils.fromUtf8("LINK"), { from: accounts[2] })108 await link.approve(dex.address, 500, {from:accounts[1]})109 await dex.deposit(100, web3.utils.fromUtf8("LINK"), {from:accounts[1]})110 //fill up the sell order111 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),1,300,{from:accounts[1]})112 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"),1,400,{from:accounts[2]})113 //check sellers's LINK balances before trade114 let account1BalanceBefore = await dex.getBalance(accounts[1], web3.utils.fromUtf8("LINK"));115 let account2BalanceBefore = await dex.getBalance(accounts[2], web3.utils.fromUtf8("LINK"));116 //accounts[1] created market order to buy up both sellers117 await dex.depositEth({value: 10000})118 await dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),2)119 //check sellers's LINK balances after trade120 let account1BalanceAfter = await dex.getBalance(accounts[1], web3.utils.fromUtf8("LINK"));121 let account2BalanceAfter = await dex.getBalance(accounts[2], web3.utils.fromUtf8("LINK"));122 assert.equal(account1BalanceBefore.toNumber()-1,account1BalanceAfter.toNumber())123 assert.equal(account2BalanceBefore.toNumber()-1,account2BalanceAfter.toNumber())124 })125 xit("Filled limit orders should be removed from the order book", async()=>{126 let dex = await Dex.deployed()127 let link = await Link.deployed()128 await dex.addToken(web3.utils.fromUtf8("LINK"), link.address)129 //Seller deposit link and creates a sell order for 1 link for 300wei130 await link.approve(dex.address, 500)131 await dex.deposit(50, web3.utils.fromUtf8("LINK"))132 await dex.depositEth({value: 10000})133 let orders = dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1) //get sell side book134 await dex.createMarketOrder(1, web3.utils.fromUtf8("LINK"), 1, 300)135 await dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),1) // accounts[0]136 orders = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1) //get sell side book137 assert(orders.length==0, "sell book isn't empty after trade")138 })139 //Limit orders filled propert should be set properly after a trade140 xit("Partially filled limit orders should be modified to present the filled/remaining amount", async()=>{141 let dex = await Dex.deployed()142 143 let orders = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1) //get sell side book144 assert(orders.length==0, "sell book isn't empty initially")145 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"), 5, 300, { from: accounts[1] })146 await dex.depositEth({value:1000})147 await dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"),2) // accounts[0]148 orders = await dex.getOrderBook(web3.utils.fromUtf8("LINK"), 1) //get sell side book149 assert.equal(orders[0].filled, 2 ,"2/5 order should be filled")150 assert.equal(orders[0].amount, 5 ,"initial amount should be 5")151 // available = amount - filled152 })153 //When creating a BUY market order, the buyer needs to have enough ETH for the trade154 it("Should throw an error when creating a buy market order without adequate ETH balance", async () => {155 let dex = await Dex.deployed()156 157 let balance = await dex.balances(accounts[4], web3.utils.fromUtf8("ETH"))158 assert.equal( balance.toNumber(), 0, "Initial ETH balance is not 0" );159 await dex.createLimitOrder(1, web3.utils.fromUtf8("LINK"), 5, 300, {from: accounts[1]})160 await truffleAssert.reverts(161 162 dex.createMarketOrder(0, web3.utils.fromUtf8("LINK"), 5, {from: accounts[4]})163 )164 })165 ...
Lab.test.js
Source:Lab.test.js
...17 assert.equal(labName, _labName, "labName is not set exactly.");18 });19 it("create Study(1)", async () => {20 await lab.createStudy("first study", 21 web3Utils.fromUtf8("noname0"), 22 web3Utils.fromUtf8("noname0@gmail.com"), 23 web3Utils.fromUtf8("https://noname0.github.io")24 );25 const count = await lab.getStudyCount();26 assert.equal(count, 1, "StudyList count is different.");27 });28 it("create Study(2)", async () => {29 await lab.createStudy("first study", 30 web3Utils.fromUtf8("noname0"), 31 web3Utils.fromUtf8("noname0@gmail.com"), 32 web3Utils.fromUtf8("https://noname0.github.io")33 );34 await lab.createStudy("second study", 35 web3Utils.fromUtf8("noname1"), 36 web3Utils.fromUtf8("noname1@gmail.com"), 37 web3Utils.fromUtf8("https://noname1.github.io")38 );39 const count = await lab.getStudyCount();40 assert.equal(count, 2, "StudyList count is different.");41 });42 it("create Study(3)", async () => {43 await lab.createStudy("first study", 44 web3Utils.fromUtf8("noname0"), 45 web3Utils.fromUtf8("noname0@gmail.com"), 46 web3Utils.fromUtf8("https://noname0.github.io")47 );48 await lab.createStudy("second study", 49 web3Utils.fromUtf8("noname1"), 50 web3Utils.fromUtf8("noname1@gmail.com"), 51 web3Utils.fromUtf8("https://noname1.github.io")52 );53 await lab.createStudy("third study", 54 web3Utils.fromUtf8("noname2"), 55 web3Utils.fromUtf8("noname2@gmail.com"), 56 web3Utils.fromUtf8("https://noname2.github.io")57 );58 const count = await lab.getStudyCount();59 assert.equal(count, 3, "StudyList count is different.");60 });...
from-utf8-test.ts
Source:from-utf8-test.ts
...18 */19import BN = require('bn.js');20import {fromUtf8} from 'susyweb-utils';21// $ExpectType string22fromUtf8('I have 100£');23// $ExpectError24fromUtf8(232);25// $ExpectError26fromUtf8(new BN(3));27// $ExpectError28fromUtf8(['string']);29// $ExpectError30fromUtf8([4]);31// $ExpectError32fromUtf8({});33// $ExpectError34fromUtf8(true);35// $ExpectError36fromUtf8(null);37// $ExpectError...
Using AI Code Generation
1var wptools = require('wptools');2var str = wptools.fromUtf8("test");3var wptools = require('wptools');4var str = wptools.fromUtf8("test");5var wptools = require('wptools');6var str = wptools.fromUtf8("test");7var wptools = require('wptools');8var str = wptools.fromUtf8("test");9var wptools = require('wptools');10var str = wptools.fromUtf8("test");11var wptools = require('wptools');12var str = wptools.fromUtf8("test");13var wptools = require('wptools');14var str = wptools.fromUtf8("test");15var wptools = require('wptools');16var str = wptools.fromUtf8("test");17var wptools = require('wptools');18var str = wptools.fromUtf8("test");19var wptools = require('wptools');20var str = wptools.fromUtf8("test");21var wptools = require('wptools');22var str = wptools.fromUtf8("test");23var wptools = require('wptools');24var str = wptools.fromUtf8("test");
Using AI Code Generation
1var wptools = require('wptools');2var result = wptools.fromUtf8('Iñtërnâtiônàlizætiøn');3console.log(result);4var wptools = require('wptools');5var result = wptools.toUtf8('Iñtërnâtiônàlizætiøn');6console.log(result);7var wptools = require('wptools');8var result = wptools.toAscii('Iñtërnâtiônàlizætiøn');9console.log(result);10var wptools = require('wptools');11var result = wptools.fromAscii('Iñtërnâtiônàlizætiøn');12console.log(result);13var wptools = require('wptools');14var result = wptools.toAscii('Iñtërnâtiônàlizætiøn');15console.log(result);16var wptools = require('wptools');17var result = wptools.fromAscii('Iñtërnâtiônàlizætiøn');18console.log(result);19var wptools = require('wptools');20var result = wptools.toAscii('Iñtërnâtiônàlizætiøn');21console.log(result);22var wptools = require('wptools');23var result = wptools.fromAscii('Iñtërnâtiônàlizætiøn');24console.log(result);25var wptools = require('wptools');26var result = wptools.toAscii('Iñtërnâtiônàl
Using AI Code Generation
1const wptools = require('wptools');2const str = 'hello world';3const utf8 = wptools.fromUtf8(str);4console.log(utf8);5const wptools = require('wptools');6const utf8 = 'hello world';7const str = wptools.toUtf8(utf8);8console.log(str);9const wptools = require('wptools');10const str = 'hello world';11const utf8 = wptools.fromUtf8(str);12console.log(utf8);13const wptools = require('wptools');14const utf8 = 'hello world';15const str = wptools.toUtf8(utf8);16console.log(str);17const wptools = require('wptools');18const str = 'hello world';19const utf8 = wptools.fromUtf8(str);20console.log(utf8);21const wptools = require('wptools');22const utf8 = 'hello world';23const str = wptools.toUtf8(utf8);24console.log(str);25const wptools = require('wptools');26const str = 'hello world';27const utf8 = wptools.fromUtf8(str);28console.log(utf8);29const wptools = require('wptools');30const utf8 = 'hello world';31const str = wptools.toUtf8(utf8);32console.log(str);33const wptools = require('wptools');34const str = 'hello world';35const utf8 = wptools.fromUtf8(str);36console.log(utf8);37const wptools = require('wptools');38const utf8 = 'hello world';39const str = wptools.toUtf8(utf8);40console.log(str);41const wptools = require('wptools');
Using AI Code Generation
1var wptools = require('wptools');2var utf8 = wptools.fromUtf8('test');3console.log(utf8);4var wptools = require('wptools');5var utf8 = wptools.fromUtf8('test');6console.log(utf8);7var wptools = require('wptools');8var utf8 = wptools.fromUtf8('test');9console.log(utf8);10var wptools = require('wptools');11var utf8 = wptools.fromUtf8('test');12console.log(utf8);13var wptools = require('wptools');14var utf8 = wptools.fromUtf8('test');15console.log(utf8);16var wptools = require('wptools');17var utf8 = wptools.fromUtf8('test');18console.log(utf8);19var wptools = require('wptools');20var utf8 = wptools.fromUtf8('test');21console.log(utf8);22var wptools = require('wptools');23var utf8 = wptools.fromUtf8('test');24console.log(utf8);25var wptools = require('wptools');26var utf8 = wptools.fromUtf8('test');27console.log(utf8);28var wptools = require('wptools');29var utf8 = wptools.fromUtf8('test');30console.log(utf8);31var wptools = require('wptools');32var utf8 = wptools.fromUtf8('test');33console.log(utf8);34var wptools = require('wptools');35var utf8 = wptools.fromUtf8('test');36console.log(utf8);
Using AI Code Generation
1var wptools = require('wptools');2var text = 'hello world';3var buffer = wptools.fromUtf8(text);4console.log(buffer);5var wptools = require('wptools');6var buffer = new Buffer('hello world');7var text = wptools.toUtf8(buffer);8console.log(text);9var wptools = require('wptools');10var buffer = new Buffer('hello world');11var text = wptools.toUtf8(buffer);12console.log(text);13var wptools = require('wptools');14var buffer = new Buffer('hello world');15var text = wptools.toUtf8(buffer);16console.log(text);17var wptools = require('wptools');18var buffer = new Buffer('hello world');19var text = wptools.toUtf8(buffer);20console.log(text);21var wptools = require('wptools');22var buffer = new Buffer('hello world');23var text = wptools.toUtf8(buffer);24console.log(text);25var wptools = require('wptools');26var buffer = new Buffer('hello world');27var text = wptools.toUtf8(buffer);28console.log(text);29var wptools = require('wptools');30var buffer = new Buffer('hello world');31var text = wptools.toUtf8(buffer);32console.log(text);33var wptools = require('wptools');34var buffer = new Buffer('hello world');35var text = wptools.toUtf8(buffer);36console.log(text);
Using AI Code Generation
1var wptools = require('wptools');2var str = wptools.fromUtf8("f0 9f 98 81");3console.log(str);4var wptools = require('wptools');5var str = wptools.toUtf8("😀");6console.log(str);7var wptools = require('wptools');8var str = wptools.toHex("😀");9console.log(str);10var wptools = require('wptools');11var str = wptools.fromHex("f09f9881");12console.log(str);13var wptools = require('wptools');14var str = wptools.toBase64("😀");15console.log(str);16var wptools = require('wptools');17var str = wptools.fromBase64("8J+YgA==");18console.log(str);19var wptools = require('wptools');20var str = wptools.toAscii("😀");21console.log(str);22var wptools = require('wptools');23var str = wptools.fromAscii("?");24console.log(str);25var wptools = require('wptools');26var str = wptools.toLatin1("😀");27console.log(str);28var wptools = require('w
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!