Best JavaScript code snippet using wpt
storage.test.ts
Source:storage.test.ts
1import { Container } from "@swipechain/core-kernel";2import { Identities, Managers, Transactions } from "@swipechain/crypto";3import { ensureFileSync } from "fs-extra";4import { Storage } from "../../../packages/core-transaction-pool/src/storage";5jest.mock("fs-extra");6const configuration = { getRequired: jest.fn() };7const container = new Container.Container();8container.bind(Container.Identifiers.PluginConfiguration).toConstantValue(configuration);9beforeEach(() => {10 configuration.getRequired.mockReset();11});12Managers.configManager.getMilestone().aip11 = true;13const transaction1 = Transactions.BuilderFactory.transfer()14 .version(2)15 .amount("100")16 .recipientId(Identities.Address.fromPassphrase("recipient's secret"))17 .nonce("1")18 .fee("900")19 .sign("sender's secret")20 .build();21const transaction2 = Transactions.BuilderFactory.transfer()22 .version(2)23 .amount("100")24 .recipientId(Identities.Address.fromPassphrase("recipient's secret"))25 .nonce("2")26 .fee("900")27 .sign("sender's secret")28 .build();29describe("Storage.boot", () => {30 it("should instantiate BetterSqlite3 using configured filename", () => {31 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage32 const storage = container.resolve(Storage);33 storage.boot();34 try {35 const database = storage["database"];36 expect(ensureFileSync).toBeCalledWith(":memory:");37 expect(database.name).toBe(":memory:");38 expect(database.open).toBe(true);39 } finally {40 storage.dispose();41 }42 });43});44describe("Storage.dispose", () => {45 it("should close database", () => {46 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage47 const storage = container.resolve(Storage);48 storage.boot();49 const database = storage["database"];50 storage.dispose();51 expect(database.open).toBe(false);52 });53});54describe("Storage.hasTransaction", () => {55 it("should find transaction that was added", () => {56 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage57 const storage = container.resolve(Storage);58 storage.boot();59 try {60 storage.addTransaction({61 height: 100,62 id: transaction1.id,63 senderPublicKey: transaction1.data.senderPublicKey,64 serialized: transaction1.serialized,65 });66 const has = storage.hasTransaction(transaction1.id);67 expect(has).toBe(true);68 } finally {69 storage.dispose();70 }71 });72 it("should not find transaction that wasn't added", () => {73 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage74 const storage = container.resolve(Storage);75 storage.boot();76 try {77 storage.addTransaction({78 height: 100,79 id: transaction1.id,80 senderPublicKey: transaction1.data.senderPublicKey,81 serialized: transaction1.serialized,82 });83 const has = storage.hasTransaction(transaction2.id);84 expect(has).toBe(false);85 } finally {86 storage.dispose();87 }88 });89});90describe("Storage.getAllTransactions", () => {91 it("should return all added transactions", () => {92 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage93 const storage = container.resolve(Storage);94 storage.boot();95 try {96 const storedTransaction1 = {97 height: 100,98 id: transaction1.id,99 senderPublicKey: transaction1.data.senderPublicKey,100 serialized: transaction1.serialized,101 };102 const storedTransaction2 = {103 height: 100,104 id: transaction2.id,105 senderPublicKey: transaction2.data.senderPublicKey,106 serialized: transaction2.serialized,107 };108 storage.addTransaction(storedTransaction1);109 storage.addTransaction(storedTransaction2);110 const allTransactions = Array.from(storage.getAllTransactions());111 expect(allTransactions).toEqual([storedTransaction1, storedTransaction2]);112 } finally {113 storage.dispose();114 }115 });116});117describe("Storage.getOldTransactions", () => {118 it("should return only old transactions", () => {119 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage120 const storage = container.resolve(Storage);121 storage.boot();122 try {123 const storedTransaction1 = {124 height: 100,125 id: transaction1.id,126 senderPublicKey: transaction1.data.senderPublicKey,127 serialized: transaction1.serialized,128 };129 const storedTransaction2 = {130 height: 200,131 id: transaction2.id,132 senderPublicKey: transaction2.data.senderPublicKey,133 serialized: transaction2.serialized,134 };135 storage.addTransaction(storedTransaction1);136 storage.addTransaction(storedTransaction2);137 const oldTransactions = Array.from(storage.getOldTransactions(100));138 expect(oldTransactions).toEqual([storedTransaction1]);139 } finally {140 storage.dispose();141 }142 });143 it("should return all old transactions", () => {144 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage145 const storage = container.resolve(Storage);146 storage.boot();147 try {148 const storedTransaction1 = {149 height: 100,150 id: transaction1.id,151 senderPublicKey: transaction1.data.senderPublicKey,152 serialized: transaction1.serialized,153 };154 const storedTransaction2 = {155 height: 200,156 id: transaction2.id,157 senderPublicKey: transaction2.data.senderPublicKey,158 serialized: transaction2.serialized,159 };160 storage.addTransaction(storedTransaction1);161 storage.addTransaction(storedTransaction2);162 const oldTransactions = Array.from(storage.getOldTransactions(200));163 expect(oldTransactions).toEqual([storedTransaction2, storedTransaction1]);164 } finally {165 storage.dispose();166 }167 });168});169describe("Storage.addTransaction", () => {170 it("should add new transaction", () => {171 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage172 const storage = container.resolve(Storage);173 storage.boot();174 try {175 storage.addTransaction({176 height: 100,177 id: transaction1.id,178 senderPublicKey: transaction1.data.senderPublicKey,179 serialized: transaction1.serialized,180 });181 const has = storage.hasTransaction(transaction1.id);182 expect(has).toBe(true);183 } finally {184 storage.dispose();185 }186 });187 it("should throw when adding same transaction twice", () => {188 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage189 const storage = container.resolve(Storage);190 storage.boot();191 try {192 storage.addTransaction({193 height: 100,194 id: transaction1.id,195 senderPublicKey: transaction1.data.senderPublicKey,196 serialized: transaction1.serialized,197 });198 expect(() => {199 storage.addTransaction({200 height: 100,201 id: transaction1.id,202 senderPublicKey: transaction1.data.senderPublicKey,203 serialized: transaction1.serialized,204 });205 }).toThrow();206 } finally {207 storage.dispose();208 }209 });210});211describe("Storage.removeTransaction", () => {212 it("should remove previously added transaction", () => {213 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage214 const storage = container.resolve(Storage);215 storage.boot();216 try {217 storage.addTransaction({218 height: 100,219 id: transaction1.id,220 senderPublicKey: transaction1.data.senderPublicKey,221 serialized: transaction1.serialized,222 });223 storage.removeTransaction(transaction1.id);224 const has = storage.hasTransaction(transaction1.id);225 expect(has).toBe(false);226 } finally {227 storage.dispose();228 }229 });230});231describe("Storage.flush", () => {232 it("should remove all previously added transactions", () => {233 configuration.getRequired.mockReturnValueOnce(":memory:"); // storage234 const storage = container.resolve(Storage);235 storage.boot();236 try {237 storage.addTransaction({238 height: 100,239 id: transaction1.id,240 senderPublicKey: transaction1.data.senderPublicKey,241 serialized: transaction1.serialized,242 });243 storage.addTransaction({244 height: 100,245 id: transaction2.id,246 senderPublicKey: transaction2.data.senderPublicKey,247 serialized: transaction2.serialized,248 });249 storage.flush();250 const allTransactions = Array.from(storage.getAllTransactions());251 expect(allTransactions).toStrictEqual([]);252 } finally {253 storage.dispose();254 }255 });...
Using AI Code Generation
1wpt.transaction1();2wpt.transaction2();3wpt.transaction3();4wpt.transaction4();5wpt.transaction5();6wpt.transaction6();7wpt.transaction7();8wpt.transaction8();9wpt.transaction9();10wpt.transaction10();11wpt.transaction11();12wpt.transaction12();13wpt.transaction13();14wpt.transaction14();15wpt.transaction15();16wpt.transaction16();17wpt.transaction17();18wpt.transaction18();19wpt.transaction19();20wpt.transaction20();21wpt.transaction21();22wpt.transaction22();
Using AI Code Generation
1wpt.transaction1();2wpt.transaction2();3wpt.transaction1();4wpt.transaction2();5wpt.transaction1();6wpt.transaction2();7wpt.transaction1();8wpt.transaction2();9wpt.transaction1();10wpt.transaction2();11wpt.transaction1();12wpt.transaction2();13wpt.transaction1();14wpt.transaction2();15wpt.transaction1();16wpt.transaction2();17wpt.transaction1();18wpt.transaction2();19wpt.transaction1();20wpt.transaction2();21wpt.transaction1();22wpt.transaction2();23wpt.transaction1();24wpt.transaction2();25wpt.transaction1();
Using AI Code Generation
1var wptest = require('wptest');2var transaction1 = wptest.transaction1;3transaction1();4var wptest = require('wptest');5var transaction2 = wptest.transaction2;6transaction2();7var wptest = require('wptest');8var transaction3 = wptest.transaction3;9transaction3();10var wptest = require('wptest');11var transaction4 = wptest.transaction4;12transaction4();13var wptest = require('wptest');14var transaction5 = wptest.transaction5;15transaction5();16var wptest = require('wptest');17var transaction6 = wptest.transaction6;18transaction6();19var wptest = require('wptest');20var transaction7 = wptest.transaction7;21transaction7();22var wptest = require('wptest');23var transaction8 = wptest.transaction8;24transaction8();25var wptest = require('wptest');26var transaction9 = wptest.transaction9;27transaction9();28var wptest = require('wptest');29var transaction10 = wptest.transaction10;30transaction10();31var wptest = require('wptest');32var transaction11 = wptest.transaction11;33transaction11();34var wptest = require('wptest');35var transaction12 = wptest.transaction12;36transaction12();37var wptest = require('wptest');38var transaction13 = wptest.transaction13;39transaction13();
Using AI Code Generation
1var wpt = require('./wpt.js');2wpt.transaction1();3module.exports = {4 transaction1: function(){5 console.log('transaction 1');6 }7}
Using AI Code Generation
1var WPT = require('wpt');2var wpt = new WPT('WPT_API_KEY');3wpt.transaction1('www.google.com', function (err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var WPT = require('wpt');11var wpt = new WPT('WPT_API_KEY');12wpt.transaction2('www.google.com', function (err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var WPT = require('wpt');20var wpt = new WPT('WPT_API_KEY');21wpt.transaction3('www.google.com', function (err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var WPT = require('wpt');29var wpt = new WPT('WPT_API_KEY');30wpt.transaction4('www.google.com', function (err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var WPT = require('wpt');38var wpt = new WPT('WPT_API_KEY');39wpt.transaction5('www.google.com', function (err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});46var WPT = require('wpt');47var wpt = new WPT('WPT_API_KEY');48wpt.transaction6('www.google.com', function (err, data) {49 if (err) {50 console.log(err);51 } else {52 console.log(data);53 }54});55var WPT = require('wpt');56var wpt = new WPT('WPT_API_KEY');
Using AI Code Generation
1var wpt = require('wpt');2 console.log('WPT transaction1: ' + data);3});4var wpt = require('wpt');5 console.log('WPT transaction2: ' + data);6});7var wpt = require('wpt');8 console.log('WPT transaction3: ' + data);9});10var wpt = require('wpt');11 console.log('WPT transaction4: ' + data);12});13var wpt = require('wpt');14 console.log('WPT transaction5: ' + data);15});16var wpt = require('wpt');17 console.log('WPT transaction6: ' + data);18});19var wpt = require('wpt');20 console.log('WPT transaction7: ' + data);21});22var wpt = require('wpt');23 console.log('WPT transaction8: ' + data);24});25var wpt = require('wpt');26 console.log('WPT transaction9: ' + data);27});28var wpt = require('wpt');
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!!