Best JavaScript code snippet using wpt
SwapValidator.js
Source:SwapValidator.js
...203 )204 errorCodes = await validator.checkSwap.call(selfOrder, {205 from: bobAddress,206 })207 const error = web3.utils.toUtf8(errorCodes[1][0])208 const error1 = web3.utils.toUtf8(errorCodes[1][1])209 equal(error, 'SELF_TRANSFER_INVALID')210 equal(error1, 'SIGNER_UNAUTHORIZED')211 equal(errorCodes[0], 2)212 })213 it('Checks error messages for invalid balances and approvals', async () => {214 const order = await signOrder(215 createOrder({216 signer: {217 wallet: aliceAddress,218 token: tokenAST.address,219 amount: 200000,220 },221 sender: {222 wallet: bobAddress,223 token: tokenAST.address,224 amount: 200000,225 },226 }),227 bobSigner,228 swapAddress229 )230 errorCodes = await validator.checkSwap.call(order, {231 from: bobAddress,232 })233 equal(errorCodes[0], 5)234 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNER_UNAUTHORIZED')235 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_BALANCE_LOW')236 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SENDER_ALLOWANCE_LOW')237 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SIGNER_BALANCE_LOW')238 equal(web3.utils.toUtf8(errorCodes[1][4]), 'SIGNER_ALLOWANCE_LOW')239 })240 it('Checks filled order emits error', async () => {241 // filled default order242 emitted(await swap(order, { from: bobAddress }), 'Swap')243 // Try to check if this order can be filled a second time244 errorCodes = await validator.checkSwap.call(order, {245 from: bobAddress,246 })247 equal(errorCodes[0], 2)248 equal(web3.utils.toUtf8(errorCodes[1][0]), 'ORDER_TAKEN_OR_CANCELLED')249 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SIGNER_ALLOWANCE_LOW')250 })251 it('Checks expired, low nonced, and invalid sig order emits error', async () => {252 emitted(await cancelUpTo(10, { from: aliceAddress }), 'CancelUpTo')253 const order = await signOrder(254 createOrder({255 signer: {256 wallet: aliceAddress,257 token: tokenAST.address,258 amount: 20,259 },260 sender: {261 wallet: bobAddress,262 token: tokenDAI.address,263 amount: 5,264 },265 expiry: (await getLatestTimestamp()) - 10, // expired time266 nonce: 5, // nonce below minimum threshold267 }),268 aliceSigner,269 swapAddress270 )271 // add an invalid signature272 order.signature.v = 3273 // Try to check if this order can be filled a second time274 errorCodes = await validator.checkSwap.call(order, {275 from: bobAddress,276 })277 equal(errorCodes[0], 3)278 equal(web3.utils.toUtf8(errorCodes[1][0]), 'ORDER_EXPIRED')279 equal(web3.utils.toUtf8(errorCodes[1][1]), 'NONCE_TOO_LOW')280 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SIGNATURE_INVALID')281 })282 it('Alice authorizes Carol to make orders on her behalf', async () => {283 emitted(284 await swapContract.authorizeSigner(eveSigner.address, {285 from: aliceAddress,286 }),287 'AuthorizeSigner'288 )289 })290 it('Check from a different approved signer and empty sender address', async () => {291 const order = await signOrder(292 createOrder({293 signer: {294 wallet: aliceAddress,295 token: tokenAST.address,296 amount: 20,297 },298 sender: {299 wallet: ADDRESS_ZERO,300 token: tokenDAI.address,301 amount: 50000,302 },303 }),304 eveSigner,305 swapAddress306 )307 order.signature.signatory = eveSigner.address308 errorCodes = await validator.checkSwap.call(order, {309 from: bobAddress,310 })311 equal(errorCodes[0], 0)312 equal(errorCodes[1][0].substring(0, 42), ADDRESS_ZERO)313 })314 })315 describe('Deploying non-fungible token...', async () => {316 it('Deployed test contract "Collectible"', async () => {317 godsUnchained = await NonFungibleToken.new()318 })319 })320 describe('Minting and testing non-fungible token...', async () => {321 it('Mints a NFT collectible (#54321) for Bob', async () => {322 emitted(await godsUnchained.mint(bobAddress, 54321), 'NFTTransfer')323 ok(324 await balances(bobAddress, [[godsUnchained, 1]]),325 'Bob balances are incorrect'326 )327 })328 it('Alice tries to buy non-owned NFT #54320 from Bob for 50 AST causes revert', async () => {329 const order = await signOrder(330 createOrder({331 signer: {332 wallet: aliceAddress,333 token: tokenAST.address,334 amount: 50,335 },336 sender: {337 wallet: bobAddress,338 token: godsUnchained.address,339 id: 54320,340 kind: tokenKinds.ERC721,341 },342 }),343 aliceSigner,344 swapAddress345 )346 await reverted(347 validator.checkSwap.call(order, { from: bobAddress }),348 'revert ERC721: owner query for nonexistent token'349 )350 })351 it('Alice tries to buy non-approved NFT #54321 from Bob for 50 AST', async () => {352 const order = await signOrder(353 createOrder({354 signer: {355 wallet: aliceAddress,356 token: tokenAST.address,357 amount: 50,358 },359 sender: {360 wallet: bobAddress,361 token: godsUnchained.address,362 id: 54321,363 kind: tokenKinds.ERC721,364 },365 }),366 aliceSigner,367 swapAddress368 )369 order.signature.version = '0x99' // incorrect version370 errorCodes = await validator.checkSwap.call(order, {371 from: bobAddress,372 })373 equal(errorCodes[0], 2)374 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNATURE_INVALID')375 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_ALLOWANCE_LOW')376 })377 })378 describe('Deploying cryptokitties...', async () => {379 it('Deployed test contract "Collectible"', async () => {380 cryptoKitties = await AdaptedKittyERC721.new()381 })382 })383 describe('Minting and testing cryptokitties...', async () => {384 it('Mints a kitty collectible (#123) for Bob and (#1) for Alice', async () => {385 emitted(await cryptoKitties.mint(bobAddress, 123), 'NFTKittyTransfer')386 emitted(await cryptoKitties.mint(aliceAddress, 1), 'NFTKittyTransfer')387 ok(388 await balances(bobAddress, [[cryptoKitties, 1]]),389 'Bob balances are incorrect'390 )391 })392 it('Alice tries to buy non-owned Kitty #124 from Bob for 50 AST causes revert', async () => {393 const order = await signOrder(394 createOrder({395 signer: {396 wallet: aliceAddress,397 token: tokenAST.address,398 amount: 50,399 },400 sender: {401 wallet: bobAddress,402 token: cryptoKitties.address,403 id: 124,404 kind: tokenKinds.CKITTY,405 },406 }),407 aliceSigner,408 swapAddress409 )410 await reverted(411 validator.checkSwap.call(order, { from: bobAddress }),412 'revert ERC721: owner query for nonexistent token'413 )414 })415 it('Alice tries to buy a token that Bob doesnt own', async () => {416 const order = await signOrder(417 createOrder({418 signer: {419 wallet: aliceAddress,420 token: tokenAST.address,421 amount: 50,422 },423 sender: {424 wallet: bobAddress,425 token: cryptoKitties.address,426 id: 1,427 kind: tokenKinds.CKITTY,428 },429 }),430 aliceSigner,431 swapAddress432 )433 errorCodes = await validator.checkSwap.call(order, {434 from: bobAddress,435 })436 equal(errorCodes[0], 2)437 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_BALANCE_LOW')438 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_ALLOWANCE_LOW')439 })440 it('Alice tries to buy non-approved Kitty #123 from Bob for 50 AST', async () => {441 const order = await signOrder(442 createOrder({443 signer: {444 wallet: aliceAddress,445 token: tokenAST.address,446 amount: 50,447 },448 sender: {449 wallet: bobAddress,450 token: cryptoKitties.address,451 id: 123,452 kind: tokenKinds.CKITTY,453 },454 }),455 aliceSigner,456 swapAddress457 )458 order.signature.version = '0x99' // incorrect version459 errorCodes = await validator.checkSwap.call(order, {460 from: bobAddress,461 })462 equal(errorCodes[0], 2)463 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNATURE_INVALID')464 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_ALLOWANCE_LOW')465 })466 })467 describe('Deploying ERC1155...', async () => {468 it('Deployed test ERC1155 Contract', async () => {469 erc1155 = await MintableERC1155.new()470 })471 })472 describe('Minting and testing ERC1155', async () => {473 it('Mints an ERC1155 collectable for Bob and Alice', async () => {474 emitted(await erc1155.mint(bobAddress, 1234, 100), 'TransferSingle')475 emitted(await erc1155.mint(aliceAddress, 3412, 1000), 'TransferSingle')476 ok(await balances(bobAddress, [[erc1155, 1234, 100]]))477 ok(await balances(aliceAddress, [[erc1155, 3412, 1000]]))478 })479 it('Alice tries to buy 10 non-owned asset #12355 from Bob for 50 AST', async () => {480 const order = await signOrder(481 createOrder({482 signer: {483 wallet: aliceAddress,484 token: tokenAST.address,485 amount: 50,486 },487 sender: {488 wallet: bobAddress,489 token: erc1155.address,490 id: 12355,491 amount: 10,492 kind: tokenKinds.ERC1155,493 },494 }),495 aliceSigner,496 swapAddress497 )498 errorCodes = await validator.checkSwap.call(order, {499 from: bobAddress,500 })501 equal(errorCodes[0], 2)502 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_BALANCE_LOW')503 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_ALLOWANCE_LOW')504 })505 it('Alice tries to buy 10 non approved asset #1234 from Bob for 50 AST', async () => {506 const order = await signOrder(507 createOrder({508 signer: {509 wallet: aliceAddress,510 token: tokenAST.address,511 amount: 50,512 },513 sender: {514 wallet: bobAddress,515 token: erc1155.address,516 id: 1234,517 amount: 10,518 kind: tokenKinds.ERC1155,519 },520 }),521 aliceSigner,522 swapAddress523 )524 order.signature.version = '0x99' // incorrect version525 errorCodes = await validator.checkSwap.call(order, {526 from: bobAddress,527 })528 equal(errorCodes[0], 2)529 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNATURE_INVALID')530 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_ALLOWANCE_LOW')531 })532 })533 describe('Swaps (Unknown token kind but valid ERC-20 tokens)', async () => {534 let order535 it('Alice creates an order for Bob (200 AST for 50 DAI) with unknown kind', async () => {536 order = await signOrder(537 createOrder({538 signer: {539 wallet: aliceAddress,540 token: tokenAST.address,541 amount: 200,542 kind: UNKNOWN_KIND,543 },544 sender: {545 wallet: bobAddress,546 token: tokenDAI.address,547 amount: 50,548 kind: UNKNOWN_KIND,549 },550 }),551 aliceSigner,552 swapAddress553 )554 })555 it('Checks malformed order errors out', async () => {556 errorCodes = await validator.checkSwap.call(order, {557 from: bobAddress,558 })559 equal(errorCodes[0], 2)560 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_TOKEN_KIND_UNKNOWN')561 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SIGNER_TOKEN_KIND_UNKNOWN')562 })563 })564 describe('Swaps (ERC20 token kind and invalid token addresses)', async () => {565 let order566 it('Alice creates an order for Bob (200 non-contract address for 50 non-contract address) will revert', async () => {567 order = await signOrder(568 createOrder({569 signer: {570 wallet: aliceAddress,571 token: aliceAddress,572 amount: 200,573 kind: tokenKinds.ERC20,574 },575 sender: {576 wallet: bobAddress,577 token: bobAddress,578 amount: 50,579 kind: tokenKinds.ERC20,580 },581 }),582 aliceSigner,583 swapAddress584 )585 })586 it('Checks malformed order reverts out', async () => {587 await reverted(588 validator.checkSwap.call(order, {589 from: bobAddress,590 })591 )592 })593 })594 describe('Swaps (ERC721 kind and invalid interface token addresses)', async () => {595 let order596 it('Alice creates an order for Bob for incorrect kind will output errors and skip balance checks', async () => {597 order = await signOrder(598 createOrder({599 signer: {600 wallet: aliceAddress,601 token: aliceAddress,602 amount: 200,603 kind: tokenKinds.ERC721,604 },605 sender: {606 wallet: bobAddress,607 token: bobAddress,608 amount: 50,609 kind: tokenKinds.ERC721,610 },611 }),612 aliceSigner,613 swapAddress614 )615 })616 it('Checks malformed order errors out', async () => {617 errorCodes = await validator.checkSwap.call(order, {618 from: bobAddress,619 })620 equal(errorCodes[0], 4)621 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_INVALID_AMOUNT')622 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SIGNER_INVALID_AMOUNT')623 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SENDER_TOKEN_KIND_MISMATCH')624 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SIGNER_TOKEN_KIND_MISMATCH')625 })626 })627 describe('Swaps (ERC20 kind and ids filled in order)', async () => {628 let order629 it('Alice creates an order for Bob for kind with invalid ids', async () => {630 order = await signOrder(631 createOrder({632 signer: {633 wallet: aliceAddress,634 token: tokenAST.address,635 id: 200,636 amount: 200,637 kind: tokenKinds.ERC20,638 },639 sender: {640 wallet: bobAddress,641 token: tokenDAI.address,642 id: 50,643 amount: 50,644 kind: tokenKinds.ERC20,645 },646 }),647 aliceSigner,648 swapAddress649 )650 })651 it('Checks malformed order errors out', async () => {652 errorCodes = await validator.checkSwap.call(order, {653 from: bobAddress,654 })655 equal(errorCodes[0], 3)656 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_INVALID_ID')657 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SIGNER_INVALID_ID')658 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SIGNER_ALLOWANCE_LOW')659 })660 })661 describe('Swaps (ERC20 kind) and invalid validator and signature', async () => {662 let order663 it('Alice creates an order for Bob for kind with invalid validator address', async () => {664 order = await signOrder(665 createOrder({666 signer: {667 wallet: aliceAddress,668 token: tokenAST.address,669 id: 200,670 amount: 200,671 kind: tokenKinds.ERC20,672 },673 sender: {674 wallet: bobAddress,675 token: tokenDAI.address,676 id: 50,677 amount: 50,678 kind: tokenKinds.ERC20,679 },680 }),681 aliceSigner,682 swapAddress683 )684 order.signature.validator = ADDRESS_ZERO685 })686 it('Checks malformed order errors out from invalid validator', async () => {687 errorCodes = await validator.checkSwap.call(order, {688 from: bobAddress,689 })690 equal(errorCodes[0], 6)691 equal(web3.utils.toUtf8(errorCodes[1][0]), 'VALIDATOR_INVALID')692 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_INVALID_ID')693 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SIGNER_INVALID_ID')694 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SIGNATURE_INVALID')695 equal(web3.utils.toUtf8(errorCodes[1][4]), 'SENDER_TOKEN_KIND_UNKNOWN')696 equal(web3.utils.toUtf8(errorCodes[1][5]), 'SIGNER_TOKEN_KIND_UNKNOWN')697 })698 })699 describe('Wrapper Buys on Swap (Fungible)', async () => {700 it('Checks that valid order has zero errors with WETH on sender wallet', async () => {701 // Bob take a WETH for DAI order from Alice using ETH702 const order = await signOrder(703 createOrder({704 signer: {705 wallet: aliceAddress,706 token: tokenAST.address,707 amount: 50,708 },709 sender: {710 wallet: bobAddress,711 token: tokenWETH.address,712 amount: 10,713 },714 }),715 aliceSigner,716 swapAddress717 )718 // Bob authorizes swap to send orders on his behalf719 // function also checks that msg.sender == order.sender.wallet720 await swapContract.authorizeSender(wrapperAddress, {721 from: bobAddress,722 })723 const errorCodes = await validator.checkWrappedSwap.call(724 order,725 bobAddress,726 wrapperAddress,727 { from: bobAddress }728 )729 equal(errorCodes[0], 0)730 equal(errorCodes[1][0].substring(0, 42), ADDRESS_ZERO)731 })732 it('Checks errors out with lack of balances and allowance on wrapper', async () => {733 // Bob take a WETH for DAI order from Alice using ETH734 const order = await signOrder(735 createOrder({736 sender: {737 wallet: aliceAddress,738 token: tokenDAI.address,739 amount: 50000,740 },741 signer: {742 wallet: bobAddress,743 token: tokenWETH.address,744 amount: 10,745 },746 }),747 aliceSigner,748 swapAddress749 )750 order.signature.v = 0751 const errorCodes = await validator.checkWrappedSwap.call(752 order,753 bobAddress,754 wrapperAddress,755 { from: bobAddress }756 )757 equal(errorCodes[0], 8)758 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNER_UNAUTHORIZED')759 equal(760 web3.utils.toUtf8(errorCodes[1][1]),761 'MSG_SENDER_MUST_BE_ORDER_SENDER'762 )763 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SENDER_UNAUTHORIZED')764 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SIGNATURE_MUST_BE_SENT')765 equal(web3.utils.toUtf8(errorCodes[1][4]), 'SENDER_WRAPPER_ALLOWANCE_LOW')766 equal(web3.utils.toUtf8(errorCodes[1][5]), 'SENDER_BALANCE_LOW')767 equal(web3.utils.toUtf8(errorCodes[1][6]), 'SENDER_ALLOWANCE_LOW')768 equal(web3.utils.toUtf8(errorCodes[1][7]), 'SIGNER_BALANCE_LOW')769 })770 it('Checks errors out with invalid validator address', async () => {771 // Bob take a WETH for DAI order from Alice using ETH772 const order = await signOrder(773 createOrder({774 sender: {775 wallet: aliceAddress,776 token: tokenDAI.address,777 amount: 50000,778 },779 signer: {780 wallet: bobAddress,781 token: tokenWETH.address,782 amount: 10,783 },784 }),785 bobSigner,786 swapAddress787 )788 order.signature.v = 0789 order.signature.validator = ADDRESS_ZERO790 const errorCodes = await validator.checkWrappedSwap.call(791 order,792 bobAddress,793 wrapperAddress,794 { from: bobAddress }795 )796 equal(errorCodes[0], 6)797 equal(web3.utils.toUtf8(errorCodes[1][0]), 'VALIDATOR_INVALID')798 equal(799 web3.utils.toUtf8(errorCodes[1][1]),800 'MSG_SENDER_MUST_BE_ORDER_SENDER'801 )802 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SIGNATURE_MUST_BE_SENT')803 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SENDER_WRAPPER_ALLOWANCE_LOW')804 equal(web3.utils.toUtf8(errorCodes[1][4]), 'SENDER_TOKEN_KIND_UNKNOWN')805 equal(web3.utils.toUtf8(errorCodes[1][5]), 'SIGNER_TOKEN_KIND_UNKNOWN')806 })807 it('Adding approval allows for zero errors and successful fill of order signer WETH', async () => {808 // Bob take a WETH for DAI order from Alice using ETH809 const order = await signOrder(810 createOrder({811 sender: {812 wallet: aliceAddress,813 token: tokenAST.address,814 amount: 50,815 },816 signer: {817 wallet: bobAddress,818 token: tokenWETH.address,819 amount: 10,820 },821 }),822 bobSigner,823 swapAddress824 )825 // Ensure bob has sufficient WETH826 await tokenWETH.deposit({ from: bobAddress, value: 10 })827 // Alice authorizes swap to send orders on his behalf828 // function also checks that msg.sender == order.sender.wallet829 await swapContract.authorizeSender(wrapperAddress, {830 from: aliceAddress,831 })832 emitted(833 await tokenWETH.approve(wrapperAddress, 10, { from: aliceAddress }),834 'Approval'835 )836 const errorCodes = await validator.checkWrappedSwap.call(837 order,838 aliceAddress,839 wrapperAddress,840 { from: aliceAddress }841 )842 equal(errorCodes[0], 0)843 // Received zero exceptions so can send to wrapper and have a successful fill844 const result = await wrapperContract.swap(order, { from: aliceAddress })845 passes(result)846 })847 it('Checks that valid order has zero errors with WETH on sender wallet', async () => {848 // Bob take a WETH for DAI order from Alice using ETH849 const order = await signOrder(850 createOrder({851 signer: {852 wallet: aliceAddress,853 token: tokenAST.address,854 amount: 50,855 },856 sender: {857 wallet: bobAddress,858 token: tokenWETH.address,859 amount: 10,860 },861 }),862 aliceSigner,863 swapAddress864 )865 // Bob authorizes swap to send orders on his behalf866 // function also checks that msg.sender == order.sender.wallet867 await swapContract.authorizeSender(wrapperAddress, {868 from: bobAddress,869 })870 const errorCodes = await validator.checkWrappedSwap.call(871 order,872 bobAddress,873 wrapperAddress,874 { from: bobAddress }875 )876 equal(errorCodes[0], 1)877 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNER_ALLOWANCE_LOW')878 emitted(879 await tokenAST.approve(swapAddress, 50, { from: aliceAddress }),880 'Approval'881 )882 // Received zero exceptions so can send to wrapper and have a successful fill883 const result = wrapperContract.swap(order, {884 from: bobAddress,885 value: 10,886 })887 passes(await result)888 })889 it('Checks that massive ETH trade will error if invalid balance', async () => {890 // Bob take a WETH for DAI order from Alice using ETH891 const order = await signOrder(892 createOrder({893 signer: {894 wallet: aliceAddress,895 token: tokenDAI.address,896 amount: '50',897 },898 sender: {899 wallet: bobAddress,900 token: tokenWETH.address,901 amount: '100000000000000000000000',902 },903 }),904 aliceSigner,905 swapAddress906 )907 const errorCodes = await validator.checkWrappedSwap.call(908 order,909 bobAddress,910 wrapperAddress,911 { from: bobAddress }912 )913 equal(errorCodes[0], 3)914 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_ETHER_LOW')915 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_ALLOWANCE_LOW')916 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SIGNER_ALLOWANCE_LOW')917 })918 })919 describe('Wrapper Receive ETH on Swap (Fungible)', async () => {920 it('Checks errors out with lack of allowance on wrapper', async () => {921 const order = await signOrder(922 createOrder({923 sender: {924 wallet: aliceAddress,925 token: tokenAST.address,926 amount: 50,927 },928 signer: {929 wallet: bobAddress,930 token: tokenWETH.address,931 amount: 10,932 },933 }),934 aliceSigner,935 swapAddress936 )937 order.signature.v = 0938 const errorCodes = await validator.checkWrappedSwap.call(939 order,940 aliceAddress,941 wrapperAddress,942 { from: aliceAddress }943 )944 equal(errorCodes[0], 5)945 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNER_UNAUTHORIZED')946 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SIGNATURE_MUST_BE_SENT')947 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SENDER_WRAPPER_ALLOWANCE_LOW')948 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SENDER_ALLOWANCE_LOW')949 equal(web3.utils.toUtf8(errorCodes[1][4]), 'SIGNER_BALANCE_LOW')950 })951 it('Checks sending empty address on sender does not break validator', async () => {952 const order = await signOrder(953 createOrder({954 signer: {955 wallet: aliceAddress,956 token: tokenAST.address,957 amount: 50,958 },959 sender: {960 wallet: ADDRESS_ZERO,961 token: tokenWETH.address,962 amount: 10,963 },964 }),965 bobSigner,966 swapAddress967 )968 order.signature.v = 0969 const errorCodes = await validator.checkWrappedSwap.call(970 order,971 aliceAddress,972 wrapperAddress,973 { from: aliceAddress }974 )975 equal(errorCodes[0], 5)976 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SIGNER_UNAUTHORIZED')977 equal(978 web3.utils.toUtf8(errorCodes[1][1]),979 'MSG_SENDER_MUST_BE_ORDER_SENDER'980 )981 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SENDER_UNAUTHORIZED')982 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SIGNATURE_MUST_BE_SENT')983 equal(web3.utils.toUtf8(errorCodes[1][4]), 'SIGNER_ALLOWANCE_LOW')984 })985 it('Adding approval allows for zero errors and successful fill of order signer WETH', async () => {986 const order = await signOrder(987 createOrder({988 sender: {989 wallet: aliceAddress,990 token: tokenAST.address,991 amount: 50,992 },993 signer: {994 wallet: bobAddress,995 token: tokenWETH.address,996 amount: 10,997 },998 }),999 bobSigner,1000 swapAddress1001 )1002 // Ensure bob has sufficient WETH1003 await tokenWETH.deposit({ from: bobAddress, value: 10 })1004 // Alice authorizes swap to send orders on his behalf1005 // function also checks that msg.sender == order.sender.wallet1006 await swapContract.authorizeSender(wrapperAddress, {1007 from: aliceAddress,1008 })1009 emitted(1010 await tokenWETH.approve(wrapperAddress, 10, { from: aliceAddress }),1011 'Approval'1012 )1013 emitted(1014 await tokenAST.approve(swapAddress, 50, { from: aliceAddress }),1015 'Approval'1016 )1017 const errorCodes = await validator.checkWrappedSwap.call(1018 order,1019 aliceAddress,1020 wrapperAddress,1021 { from: aliceAddress }1022 )1023 equal(errorCodes[0], 0)1024 // Received zero exceptions so can send to wrapper and have a successful fill1025 let result = await wrapperContract.swap(order, { from: aliceAddress })1026 passes(result)1027 result = await getResult(swapContract, result.tx)1028 emitted(result, 'Swap')1029 })1030 it('Checks inserting unknown kind outputs error', async () => {1031 const order = await signOrder(1032 createOrder({1033 sender: {1034 wallet: aliceAddress,1035 token: tokenAST.address,1036 amount: 50,1037 kind: UNKNOWN_KIND,1038 },1039 signer: {1040 wallet: bobAddress,1041 token: tokenWETH.address,1042 amount: 10,1043 kind: UNKNOWN_KIND,1044 },1045 }),1046 bobSigner,1047 swapAddress1048 )1049 // Bob authorizes swap to send orders on his behalf1050 // function also checks that msg.sender == order.sender.wallet1051 await swapContract.authorizeSender(wrapperAddress, {1052 from: bobAddress,1053 })1054 const errorCodes = await validator.checkWrappedSwap.call(1055 order,1056 aliceAddress,1057 wrapperAddress,1058 { from: aliceAddress }1059 )1060 equal(errorCodes[0], 3)1061 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_WRAPPER_ALLOWANCE_LOW')1062 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SENDER_TOKEN_KIND_UNKNOWN')1063 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SIGNER_TOKEN_KIND_UNKNOWN')1064 })1065 it('Checks malformed order errors out', async () => {1066 const order = await signOrder(1067 createOrder({1068 signer: {1069 wallet: aliceAddress,1070 token: tokenAST.address,1071 amount: 200,1072 kind: tokenKinds.ERC721,1073 },1074 sender: {1075 wallet: bobAddress,1076 token: tokenWETH.address,1077 amount: 50,1078 kind: tokenKinds.ERC721,1079 },1080 }),1081 aliceSigner,1082 swapAddress1083 )1084 errorCodes = await validator.checkWrappedSwap.call(1085 order,1086 bobAddress,1087 wrapperAddress,1088 {1089 from: bobAddress,1090 }1091 )1092 equal(errorCodes[0], 4)1093 equal(web3.utils.toUtf8(errorCodes[1][0]), 'SENDER_INVALID_AMOUNT')1094 equal(web3.utils.toUtf8(errorCodes[1][1]), 'SIGNER_INVALID_AMOUNT')1095 equal(web3.utils.toUtf8(errorCodes[1][2]), 'SENDER_TOKEN_KIND_MISMATCH')1096 equal(web3.utils.toUtf8(errorCodes[1][3]), 'SIGNER_TOKEN_KIND_MISMATCH')1097 })1098 })...
CandidateList.js
Source:CandidateList.js
...43 for(let i=0;i<numofcandidate;i++){44 getCandidate(i+1,(err,result) => {45 if(err) console.error('An error occured ::', err);46 //console.log(result);47 console.log(web3.toUtf8(result[0]));48 this.handleAddCandidate(web3.toUtf8(result[0]),web3.toUtf8(result[2]))49 // console.log(web3.toUtf8(result[1]));50 // console.log(web3.toUtf8(result[2]));51 })52 }53 })54}55 queryCandidateDetails (event){56 let web3 = store.getState().web3.web3Instance57 var candidateContractInstance;58 candidateContractInstance=web3.eth.contract(candidateContract).at('0x8B74F1C1235f2dC2821338bcA739cD70306D394F')59 const candidateID = this.state.candidateid;60 console.log(candidateID)61 const { getCandidate } = candidateContractInstance;62 getCandidate(candidateID,(err,result) => {63 if(err) console.error('An error occured ::', err);64 // console.log(web3.toUtf8(result[3]));65 // console.log(web3.toUtf8(result[1]));66 // console.log(web3.toUtf8(result[2]));67 // console.log(web3.toUtf8(result[1]))68 this.setState({69 name: web3.toUtf8(result[0]),70 nic:web3.toUtf8(result[1]),71 party:web3.toUtf8(result[2])72 })73 })74 event.preventDefault()75 }76 render(){77 return(78 <Segment placeholder>79 <Grid columns={2} relaxed='very' stackable>80 <Grid.Column>81 <Form>82 <h4>Candidates</h4>83 {this.state.candidates.map((candidate,i) => (84 <Form.Field key={i}>85 <Label as='a' image>...
to-utf8-test.ts
Source:to-utf8-test.ts
...18 */19import BN = require('bn.js');20import {toUtf8} from 'web3-utils';21// $ExpectType string22toUtf8('0x49206861766520313030e282ac');23// $ExpectError24toUtf8(656);25// $ExpectError26toUtf8(new BN(3));27// $ExpectError28toUtf8(['string']);29// $ExpectError30toUtf8([4]);31// $ExpectError32toUtf8({});33// $ExpectError34toUtf8(true);35// $ExpectError36toUtf8(null);37// $ExpectError...
Using AI Code Generation
1var wptools = require('wptools');2var data = wptools.toUtf8('test');3var wptools = require('wptools');4var data = wptools.toUtf8('test');5var wptools = require('wptools');6var data = wptools.toUtf8('test');7var wptools = require('wptools');8var data = wptools.toUtf8('test');9var wptools = require('wptools');10var data = wptools.toUtf8('test');11var wptools = require('wptools');12var data = wptools.toUtf8('test');13var wptools = require('wptools');14var data = wptools.toUtf8('test');15var wptools = require('wptools');16var data = wptools.toUtf8('test');17var wptools = require('wptools');18var data = wptools.toUtf8('test');19var wptools = require('wptools');20var data = wptools.toUtf8('test');21var wptools = require('wptools');22var data = wptools.toUtf8('test');23var wptools = require('wptools');24var data = wptools.toUtf8('test');
Using AI Code Generation
1var wptexturize = require('wptexturize');2console.log(wptexturize.toUtf8('“”‘’…–—'));3console.log(wptexturize.toHtmlEntities('“”‘’…–—'));4console.log(wptexturize.toHtmlNumericEntities('“”‘’…–—'));5console.log(wptexturize.toHtmlEntitiesAll('“”‘’…–—'));6console.log(wptexturize.toHtmlNumericEntitiesAll('“”‘’…–—'));7console.log(wptexturize.toHtml('“”‘’…–—'));8console.log(wptexturize.toHtmlAll('“”‘’…–—'));9console.log(wptexturize.toHtmlAll('“”‘’…–—', {convertQuotes: false}));10console.log(wptexturize.toHtmlAll('“”‘’…–—', {convertQuotes: true}));
Using AI Code Generation
1var wptexturize = require('wptexturize');2var str = wptexturize.toUtf8('test');3var wptexturize = require('wptexturize');4var str = wptexturize.toUtf8('test');5var wptexturize = require('wptexturize');6var str = wptexturize.toUtf8('test');7var wptexturize = require('wptexturize');8var str = wptexturize.toUtf8('test');9var wptexturize = require('wptexturize');10var str = wptexturize.toUtf8('test');11var wptexturize = require('wptexturize');12var str = wptexturize.toUtf8('test');13var wptexturize = require('wptexturize');14var str = wptexturize.toUtf8('test');15var wptexturize = require('wptexturize');16var str = wptexturize.toUtf8('test');17var wptexturize = require('wptexturize');18var str = wptexturize.toUtf8('test');19var wptexturize = require('wptexturize');
Using AI Code Generation
1const wptools = require("wptools");2var utf8 = wptools.toUtf8("Hello World!");3console.log(utf8);4var utf8 = require("wptools").toUtf8("Hello World!");5console.log(utf8);6var wptools = require("wptools");7var utf8 = wptools.toUtf8("Hello World!");8console.log(utf8);9var wptools = require("wptools");10var utf8 = wptools.toUtf8("Hello World!");11console.log(utf8);12var wptools = require("wptools");13var utf8 = wptools.toUtf8("Hello World!");14console.log(utf8);15var wptools = require("wptools");16var utf8 = wptools.toUtf8("Hello World!");17console.log(utf8);18var wptools = require("wptools");19var utf8 = wptools.toUtf8("Hello World!");20console.log(utf8);21var wptools = require("wptools");22var utf8 = wptools.toUtf8("Hello World!");23console.log(utf8);24var wptools = require("wptools");25var utf8 = wptools.toUtf8("Hello World!");26console.log(utf8);27var wptools = require("wptools");28var utf8 = wptools.toUtf8("Hello World!");29console.log(utf8);30var wptools = require("wptools");31var utf8 = wptools.toUtf8("Hello World!");32console.log(utf8);33var wptools = require("wptools");34var utf8 = wptools.toUtf8("Hello World!");35console.log(utf8);
Using AI Code Generation
1var wptexturize = require('wptexturize');2var str = 'I am a string';3var utf8 = wptexturize.toUtf8(str);4var wptexturize = require('wptexturize');5var str = 'I am a string';6var entities = wptexturize.toEntities(str);7var wptexturize = require('wptexturize');8var str = 'I am a string';9var entities = wptexturize.toEntities(str);10var wptexturize = require('wptexturize');11var str = 'I am a string';12var entities = wptexturize.toEntities(str);13var wptexturize = require('wptexturize');14var str = 'I am a string';15var entities = wptexturize.toEntities(str);16var wptexturize = require('wptexturize');17var str = 'I am a string';18var entities = wptexturize.toEntities(str);19var wptexturize = require('wptexturize');20var str = 'I am a string';21var entities = wptexturize.toEntities(str);22var wptexturize = require('wptexturize');23var str = 'I am a string';24var entities = wptexturize.toEntities(str);25var wptexturize = require('wptexturize');26var str = 'I am a string';27var entities = wptexturize.toEntities(str);28var wptexturize = require('wptexturize');29var str = 'I am a string';
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!!