How to use transaction method in wpt

Best JavaScript code snippet using wpt

collation.test.ts

Source:collation.test.ts Github

copy

Full Screen

1import { StorageInterface } from "@marubase/storage";2import { expect } from "chai";3export function collationTest(storageFn: () => StorageInterface): void {4 describe("Collation", function () {5 let storage: StorageInterface;6 beforeEach(async function () {7 storage = storageFn();8 });9 afterEach(async function () {10 const { asc, desc } = storage.order;11 await storage.bucket("test").clearRange(asc(null), desc(null));12 });13 context("insert different key type in ascending order", function () {14 it("should return ordered entry", async function () {15 const { asc, desc } = storage.order;16 await storage.write("test", async (transaction) => {17 transaction.bucket("test").set(asc(false), true);18 transaction.bucket("test").set(asc(true), true);19 const { int8, uint8 } = transaction.cast;20 transaction.bucket("test").set(asc(int8(-128)), true);21 transaction.bucket("test").set(asc(int8(0)), true);22 transaction.bucket("test").set(asc(int8(127)), true);23 transaction.bucket("test").set(asc(uint8(0)), true);24 transaction.bucket("test").set(asc(uint8(255)), true);25 const { int16, uint16 } = transaction.cast;26 transaction.bucket("test").set(asc(int16(-32768)), true);27 transaction.bucket("test").set(asc(int16(0)), true);28 transaction.bucket("test").set(asc(int16(32767)), true);29 transaction.bucket("test").set(asc(uint16(0)), true);30 transaction.bucket("test").set(asc(uint16(65535)), true);31 const { int32, uint32 } = transaction.cast;32 transaction.bucket("test").set(asc(int32(-2147483648)), true);33 transaction.bucket("test").set(asc(int32(0)), true);34 transaction.bucket("test").set(asc(int32(2147483647)), true);35 transaction.bucket("test").set(asc(uint32(0)), true);36 transaction.bucket("test").set(asc(uint32(4294967295)), true);37 const { int64, uint64 } = transaction.cast;38 transaction39 .bucket("test")40 .set(asc(int64(-9223372036854775808n)), true);41 transaction.bucket("test").set(asc(int64(0n)), true);42 transaction43 .bucket("test")44 .set(asc(int64(9223372036854775807n)), true);45 transaction.bucket("test").set(asc(uint64(0n)), true);46 transaction47 .bucket("test")48 .set(asc(uint64(18446744073709551615n)), true);49 const { float32 } = transaction.cast;50 transaction.bucket("test").set(asc(float32(-Infinity)), true);51 transaction.bucket("test").set(asc(float32(0)), true);52 transaction.bucket("test").set(asc(float32(Infinity)), true);53 const { float64 } = transaction.cast;54 transaction.bucket("test").set(asc(float64(-Infinity)), true);55 transaction.bucket("test").set(asc(float64(-Math.PI)), true);56 transaction.bucket("test").set(asc(float64(-Math.E)), true);57 transaction.bucket("test").set(asc(float64(0)), true);58 transaction.bucket("test").set(asc(float64(Math.E)), true);59 transaction.bucket("test").set(asc(float64(Math.PI)), true);60 transaction.bucket("test").set(asc(float64(Infinity)), true);61 transaction.bucket("test").set(asc(new Date(-1000)), true);62 transaction.bucket("test").set(asc(new Date(1000)), true);63 transaction.bucket("test").set(asc(Buffer.from([0])), true);64 transaction.bucket("test").set(asc(Buffer.from([255])), true);65 transaction.bucket("test").set(asc("a"), true);66 transaction.bucket("test").set(asc("z"), true);67 transaction.bucket("test").set(asc([false, true]), true);68 transaction.bucket("test").set(asc([true, true]), true);69 transaction.bucket("test").set(asc([int8(-128), true]), true);70 transaction.bucket("test").set(asc([int8(0), true]), true);71 transaction.bucket("test").set(asc([int8(127), true]), true);72 transaction.bucket("test").set(asc([uint8(0), true]), true);73 transaction.bucket("test").set(asc([uint8(255), true]), true);74 transaction.bucket("test").set(asc([int16(-32768), true]), true);75 transaction.bucket("test").set(asc([int16(0), true]), true);76 transaction.bucket("test").set(asc([int16(32767), true]), true);77 transaction.bucket("test").set(asc([uint16(0), true]), true);78 transaction.bucket("test").set(asc([uint16(65535), true]), true);79 transaction.bucket("test").set(asc([int32(-2147483648), true]), true);80 transaction.bucket("test").set(asc([int32(0), true]), true);81 transaction.bucket("test").set(asc([int32(2147483647), true]), true);82 transaction.bucket("test").set(asc([uint32(0), true]), true);83 transaction.bucket("test").set(asc([uint32(4294967295), true]), true);84 transaction85 .bucket("test")86 .set(asc([int64(-9223372036854775808n), true]), true);87 transaction.bucket("test").set(asc([int64(0n), true]), true);88 transaction89 .bucket("test")90 .set(asc([int64(9223372036854775807n), true]), true);91 transaction.bucket("test").set(asc([uint64(0n), true]), true);92 transaction93 .bucket("test")94 .set(asc([uint64(18446744073709551615n), true]), true);95 transaction.bucket("test").set(asc([float32(-Infinity), true]), true);96 transaction.bucket("test").set(asc([float32(0), true]), true);97 transaction.bucket("test").set(asc([float32(Infinity), true]), true);98 transaction.bucket("test").set(asc([float64(-Infinity), true]), true);99 transaction.bucket("test").set(asc([float64(-Math.PI), true]), true);100 transaction.bucket("test").set(asc([float64(-Math.E), true]), true);101 transaction.bucket("test").set(asc([float64(0), true]), true);102 transaction.bucket("test").set(asc([float64(Math.E), true]), true);103 transaction.bucket("test").set(asc([float64(Math.PI), true]), true);104 transaction.bucket("test").set(asc([float64(Infinity), true]), true);105 transaction.bucket("test").set(asc([new Date(-1000), true]), true);106 transaction.bucket("test").set(asc([new Date(1000), true]), true);107 transaction.bucket("test").set(asc([Buffer.from([0]), true]), true);108 transaction.bucket("test").set(asc([Buffer.from([255]), true]), true);109 transaction.bucket("test").set(asc(["a", true]), true);110 transaction.bucket("test").set(asc(["z", true]), true);111 transaction.bucket("test").set(asc({ a: false }), true);112 transaction.bucket("test").set(asc({ a: true }), true);113 transaction.bucket("test").set(asc({ a: int8(-128) }), true);114 transaction.bucket("test").set(asc({ a: int8(0) }), true);115 transaction.bucket("test").set(asc({ a: int8(127) }), true);116 transaction.bucket("test").set(asc({ a: uint8(0) }), true);117 transaction.bucket("test").set(asc({ a: uint8(255) }), true);118 transaction.bucket("test").set(asc({ a: int16(-32768) }), true);119 transaction.bucket("test").set(asc({ a: int16(0) }), true);120 transaction.bucket("test").set(asc({ a: int16(32767) }), true);121 transaction.bucket("test").set(asc({ a: uint16(0) }), true);122 transaction.bucket("test").set(asc({ a: uint16(65535) }), true);123 transaction.bucket("test").set(asc({ a: int32(-2147483648) }), true);124 transaction.bucket("test").set(asc({ a: int32(0) }), true);125 transaction.bucket("test").set(asc({ a: int32(2147483647) }), true);126 transaction.bucket("test").set(asc({ a: uint32(0) }), true);127 transaction.bucket("test").set(asc({ a: uint32(4294967295) }), true);128 transaction129 .bucket("test")130 .set(asc({ a: int64(-9223372036854775808n) }), true);131 transaction.bucket("test").set(asc({ a: int64(0n) }), true);132 transaction133 .bucket("test")134 .set(asc({ a: int64(9223372036854775807n) }), true);135 transaction.bucket("test").set(asc({ a: uint64(0n) }), true);136 transaction137 .bucket("test")138 .set(asc({ a: uint64(18446744073709551615n) }), true);139 transaction.bucket("test").set(asc({ a: float32(-Infinity) }), true);140 transaction.bucket("test").set(asc({ a: float32(0) }), true);141 transaction.bucket("test").set(asc({ a: float32(Infinity) }), true);142 transaction.bucket("test").set(asc({ a: float64(-Infinity) }), true);143 transaction.bucket("test").set(asc({ a: float64(-Math.PI) }), true);144 transaction.bucket("test").set(asc({ a: float64(-Math.E) }), true);145 transaction.bucket("test").set(asc({ a: float64(0) }), true);146 transaction.bucket("test").set(asc({ a: float64(Math.E) }), true);147 transaction.bucket("test").set(asc({ a: float64(Math.PI) }), true);148 transaction.bucket("test").set(asc({ a: float64(Infinity) }), true);149 transaction.bucket("test").set(asc({ a: new Date(-1000) }), true);150 transaction.bucket("test").set(asc({ a: new Date(1000) }), true);151 transaction.bucket("test").set(asc({ a: Buffer.from([0]) }), true);152 transaction.bucket("test").set(asc({ a: Buffer.from([255]) }), true);153 transaction.bucket("test").set(asc({ a: "a" }), true);154 transaction.bucket("test").set(asc({ a: "z" }), true);155 });156 const collection = await storage157 .bucket("test")158 .getRange(asc(null), desc(null));159 expect(collection).to.deep.equal([160 [false, true],161 [true, true],162 [-128, true],163 [0, true],164 [127, true],165 [0, true],166 [255, true],167 [-32768, true],168 [0, true],169 [32767, true],170 [0, true],171 [65535, true],172 [-2147483648, true],173 [0, true],174 [2147483647, true],175 [0, true],176 [4294967295, true],177 [-9223372036854775808n, true],178 [0n, true],179 [9223372036854775807n, true],180 [0n, true],181 [18446744073709551615n, true],182 [-Infinity, true],183 [0, true],184 [Infinity, true],185 [-Infinity, true],186 [-Math.PI, true],187 [-Math.E, true],188 [0, true],189 [Math.E, true],190 [Math.PI, true],191 [Infinity, true],192 [new Date(-1000), true],193 [new Date(1000), true],194 [Buffer.from([0]), true],195 [Buffer.from([255]), true],196 ["a", true],197 ["z", true],198 [[false, true], true],199 [[true, true], true],200 [[-128, true], true],201 [[0, true], true],202 [[127, true], true],203 [[0, true], true],204 [[255, true], true],205 [[-32768, true], true],206 [[0, true], true],207 [[32767, true], true],208 [[0, true], true],209 [[65535, true], true],210 [[-2147483648, true], true],211 [[0, true], true],212 [[2147483647, true], true],213 [[0, true], true],214 [[4294967295, true], true],215 [[-9223372036854775808n, true], true],216 [[0n, true], true],217 [[9223372036854775807n, true], true],218 [[0n, true], true],219 [[18446744073709551615n, true], true],220 [[-Infinity, true], true],221 [[0, true], true],222 [[Infinity, true], true],223 [[-Infinity, true], true],224 [[-Math.PI, true], true],225 [[-Math.E, true], true],226 [[0, true], true],227 [[Math.E, true], true],228 [[Math.PI, true], true],229 [[Infinity, true], true],230 [[new Date(-1000), true], true],231 [[new Date(1000), true], true],232 [[Buffer.from([0]), true], true],233 [[Buffer.from([255]), true], true],234 [["a", true], true],235 [["z", true], true],236 [{ a: false }, true],237 [{ a: true }, true],238 [{ a: -128 }, true],239 [{ a: 0 }, true],240 [{ a: 127 }, true],241 [{ a: 0 }, true],242 [{ a: 255 }, true],243 [{ a: -32768 }, true],244 [{ a: 0 }, true],245 [{ a: 32767 }, true],246 [{ a: 0 }, true],247 [{ a: 65535 }, true],248 [{ a: -2147483648 }, true],249 [{ a: 0 }, true],250 [{ a: 2147483647 }, true],251 [{ a: 0 }, true],252 [{ a: 4294967295 }, true],253 [{ a: -9223372036854775808n }, true],254 [{ a: 0n }, true],255 [{ a: 9223372036854775807n }, true],256 [{ a: 0n }, true],257 [{ a: 18446744073709551615n }, true],258 [{ a: -Infinity }, true],259 [{ a: 0 }, true],260 [{ a: Infinity }, true],261 [{ a: -Infinity }, true],262 [{ a: -Math.PI }, true],263 [{ a: -Math.E }, true],264 [{ a: 0 }, true],265 [{ a: Math.E }, true],266 [{ a: Math.PI }, true],267 [{ a: Infinity }, true],268 [{ a: new Date(-1000) }, true],269 [{ a: new Date(1000) }, true],270 [{ a: Buffer.from([0]) }, true],271 [{ a: Buffer.from([255]) }, true],272 [{ a: "a" }, true],273 [{ a: "z" }, true],274 ]);275 });276 });277 context("insert different key type in descending order", function () {278 it("should return ordered entry", async function () {279 const { asc, desc } = storage.order;280 await storage.write("test", async (transaction) => {281 transaction.bucket("test").set(desc(false), true);282 transaction.bucket("test").set(desc(true), true);283 const { int8, uint8 } = transaction.cast;284 transaction.bucket("test").set(desc(int8(-128)), true);285 transaction.bucket("test").set(desc(int8(0)), true);286 transaction.bucket("test").set(desc(int8(127)), true);287 transaction.bucket("test").set(desc(uint8(0)), true);288 transaction.bucket("test").set(desc(uint8(255)), true);289 const { int16, uint16 } = transaction.cast;290 transaction.bucket("test").set(desc(int16(-32768)), true);291 transaction.bucket("test").set(desc(int16(0)), true);292 transaction.bucket("test").set(desc(int16(32767)), true);293 transaction.bucket("test").set(desc(uint16(0)), true);294 transaction.bucket("test").set(desc(uint16(65535)), true);295 const { int32, uint32 } = transaction.cast;296 transaction.bucket("test").set(desc(int32(-2147483648)), true);297 transaction.bucket("test").set(desc(int32(0)), true);298 transaction.bucket("test").set(desc(int32(2147483647)), true);299 transaction.bucket("test").set(desc(uint32(0)), true);300 transaction.bucket("test").set(desc(uint32(4294967295)), true);301 const { int64, uint64 } = transaction.cast;302 transaction303 .bucket("test")304 .set(desc(int64(-9223372036854775808n)), true);305 transaction.bucket("test").set(desc(int64(0n)), true);306 transaction307 .bucket("test")308 .set(desc(int64(9223372036854775807n)), true);309 transaction.bucket("test").set(desc(uint64(0n)), true);310 transaction311 .bucket("test")312 .set(desc(uint64(18446744073709551615n)), true);313 const { float32 } = transaction.cast;314 transaction.bucket("test").set(desc(float32(-Infinity)), true);315 transaction.bucket("test").set(desc(float32(0)), true);316 transaction.bucket("test").set(desc(float32(Infinity)), true);317 const { float64 } = transaction.cast;318 transaction.bucket("test").set(desc(float64(-Infinity)), true);319 transaction.bucket("test").set(desc(float64(-Math.PI)), true);320 transaction.bucket("test").set(desc(float64(-Math.E)), true);321 transaction.bucket("test").set(desc(float64(0)), true);322 transaction.bucket("test").set(desc(float64(Math.E)), true);323 transaction.bucket("test").set(desc(float64(Math.PI)), true);324 transaction.bucket("test").set(desc(float64(Infinity)), true);325 transaction.bucket("test").set(desc(new Date(-1000)), true);326 transaction.bucket("test").set(desc(new Date(1000)), true);327 transaction.bucket("test").set(desc(Buffer.from([0])), true);328 transaction.bucket("test").set(desc(Buffer.from([255])), true);329 transaction.bucket("test").set(desc("a"), true);330 transaction.bucket("test").set(desc("z"), true);331 transaction.bucket("test").set(desc([false, true]), true);332 transaction.bucket("test").set(desc([true, true]), true);333 transaction.bucket("test").set(desc([int8(-128), true]), true);334 transaction.bucket("test").set(desc([int8(0), true]), true);335 transaction.bucket("test").set(desc([int8(127), true]), true);336 transaction.bucket("test").set(desc([uint8(0), true]), true);337 transaction.bucket("test").set(desc([uint8(255), true]), true);338 transaction.bucket("test").set(desc([int16(-32768), true]), true);339 transaction.bucket("test").set(desc([int16(0), true]), true);340 transaction.bucket("test").set(desc([int16(32767), true]), true);341 transaction.bucket("test").set(desc([uint16(0), true]), true);342 transaction.bucket("test").set(desc([uint16(65535), true]), true);343 transaction344 .bucket("test")345 .set(desc([int32(-2147483648), true]), true);346 transaction.bucket("test").set(desc([int32(0), true]), true);347 transaction.bucket("test").set(desc([int32(2147483647), true]), true);348 transaction.bucket("test").set(desc([uint32(0), true]), true);349 transaction350 .bucket("test")351 .set(desc([uint32(4294967295), true]), true);352 transaction353 .bucket("test")354 .set(desc([int64(-9223372036854775808n), true]), true);355 transaction.bucket("test").set(desc([int64(0n), true]), true);356 transaction357 .bucket("test")358 .set(desc([int64(9223372036854775807n), true]), true);359 transaction.bucket("test").set(desc([uint64(0n), true]), true);360 transaction361 .bucket("test")362 .set(desc([uint64(18446744073709551615n), true]), true);363 transaction364 .bucket("test")365 .set(desc([float32(-Infinity), true]), true);366 transaction.bucket("test").set(desc([float32(0), true]), true);367 transaction.bucket("test").set(desc([float32(Infinity), true]), true);368 transaction369 .bucket("test")370 .set(desc([float64(-Infinity), true]), true);371 transaction.bucket("test").set(desc([float64(-Math.PI), true]), true);372 transaction.bucket("test").set(desc([float64(-Math.E), true]), true);373 transaction.bucket("test").set(desc([float64(0), true]), true);374 transaction.bucket("test").set(desc([float64(Math.E), true]), true);375 transaction.bucket("test").set(desc([float64(Math.PI), true]), true);376 transaction.bucket("test").set(desc([float64(Infinity), true]), true);377 transaction.bucket("test").set(desc([new Date(-1000), true]), true);378 transaction.bucket("test").set(desc([new Date(1000), true]), true);379 transaction.bucket("test").set(desc([Buffer.from([0]), true]), true);380 transaction381 .bucket("test")382 .set(desc([Buffer.from([255]), true]), true);383 transaction.bucket("test").set(desc(["a", true]), true);384 transaction.bucket("test").set(desc(["z", true]), true);385 transaction.bucket("test").set(desc({ a: false }), true);386 transaction.bucket("test").set(desc({ a: true }), true);387 transaction.bucket("test").set(desc({ a: int8(-128) }), true);388 transaction.bucket("test").set(desc({ a: int8(0) }), true);389 transaction.bucket("test").set(desc({ a: int8(127) }), true);390 transaction.bucket("test").set(desc({ a: uint8(0) }), true);391 transaction.bucket("test").set(desc({ a: uint8(255) }), true);392 transaction.bucket("test").set(desc({ a: int16(-32768) }), true);393 transaction.bucket("test").set(desc({ a: int16(0) }), true);394 transaction.bucket("test").set(desc({ a: int16(32767) }), true);395 transaction.bucket("test").set(desc({ a: uint16(0) }), true);396 transaction.bucket("test").set(desc({ a: uint16(65535) }), true);397 transaction.bucket("test").set(desc({ a: int32(-2147483648) }), true);398 transaction.bucket("test").set(desc({ a: int32(0) }), true);399 transaction.bucket("test").set(desc({ a: int32(2147483647) }), true);400 transaction.bucket("test").set(desc({ a: uint32(0) }), true);401 transaction.bucket("test").set(desc({ a: uint32(4294967295) }), true);402 transaction403 .bucket("test")404 .set(desc({ a: int64(-9223372036854775808n) }), true);405 transaction.bucket("test").set(desc({ a: int64(0n) }), true);406 transaction407 .bucket("test")408 .set(desc({ a: int64(9223372036854775807n) }), true);409 transaction.bucket("test").set(desc({ a: uint64(0n) }), true);410 transaction411 .bucket("test")412 .set(desc({ a: uint64(18446744073709551615n) }), true);413 transaction.bucket("test").set(desc({ a: float32(-Infinity) }), true);414 transaction.bucket("test").set(desc({ a: float32(0) }), true);415 transaction.bucket("test").set(desc({ a: float32(Infinity) }), true);416 transaction.bucket("test").set(desc({ a: float64(-Infinity) }), true);417 transaction.bucket("test").set(desc({ a: float64(-Math.PI) }), true);418 transaction.bucket("test").set(desc({ a: float64(-Math.E) }), true);419 transaction.bucket("test").set(desc({ a: float64(0) }), true);420 transaction.bucket("test").set(desc({ a: float64(Math.E) }), true);421 transaction.bucket("test").set(desc({ a: float64(Math.PI) }), true);422 transaction.bucket("test").set(desc({ a: float64(Infinity) }), true);423 transaction.bucket("test").set(desc({ a: new Date(-1000) }), true);424 transaction.bucket("test").set(desc({ a: new Date(1000) }), true);425 transaction.bucket("test").set(desc({ a: Buffer.from([0]) }), true);426 transaction.bucket("test").set(desc({ a: Buffer.from([255]) }), true);427 transaction.bucket("test").set(desc({ a: "a" }), true);428 transaction.bucket("test").set(desc({ a: "z" }), true);429 });430 const collection = await storage431 .bucket("test")432 .getRange(asc(null), desc(null));433 expect(collection).to.deep.equal([434 [{ a: "z" }, true],435 [{ a: "a" }, true],436 [{ a: Buffer.from([255]) }, true],437 [{ a: Buffer.from([0]) }, true],438 [{ a: new Date(1000) }, true],439 [{ a: new Date(-1000) }, true],440 [{ a: Infinity }, true],441 [{ a: Math.PI }, true],442 [{ a: Math.E }, true],443 [{ a: 0 }, true],444 [{ a: -Math.E }, true],445 [{ a: -Math.PI }, true],446 [{ a: -Infinity }, true],447 [{ a: Infinity }, true],448 [{ a: 0 }, true],449 [{ a: -Infinity }, true],450 [{ a: 18446744073709551615n }, true],451 [{ a: 0n }, true],452 [{ a: 9223372036854775807n }, true],453 [{ a: 0n }, true],454 [{ a: -9223372036854775808n }, true],455 [{ a: 4294967295 }, true],456 [{ a: 0 }, true],457 [{ a: 2147483647 }, true],458 [{ a: 0 }, true],459 [{ a: -2147483648 }, true],460 [{ a: 65535 }, true],461 [{ a: 0 }, true],462 [{ a: 32767 }, true],463 [{ a: 0 }, true],464 [{ a: -32768 }, true],465 [{ a: 255 }, true],466 [{ a: 0 }, true],467 [{ a: 127 }, true],468 [{ a: 0 }, true],469 [{ a: -128 }, true],470 [{ a: true }, true],471 [{ a: false }, true],472 [["z", true], true],473 [["a", true], true],474 [[Buffer.from([255]), true], true],475 [[Buffer.from([0]), true], true],476 [[new Date(1000), true], true],477 [[new Date(-1000), true], true],478 [[Infinity, true], true],479 [[Math.PI, true], true],480 [[Math.E, true], true],481 [[0, true], true],482 [[-Math.E, true], true],483 [[-Math.PI, true], true],484 [[-Infinity, true], true],485 [[Infinity, true], true],486 [[0, true], true],487 [[-Infinity, true], true],488 [[18446744073709551615n, true], true],489 [[0n, true], true],490 [[9223372036854775807n, true], true],491 [[0n, true], true],492 [[-9223372036854775808n, true], true],493 [[4294967295, true], true],494 [[0, true], true],495 [[2147483647, true], true],496 [[0, true], true],497 [[-2147483648, true], true],498 [[65535, true], true],499 [[0, true], true],500 [[32767, true], true],501 [[0, true], true],502 [[-32768, true], true],503 [[255, true], true],504 [[0, true], true],505 [[127, true], true],506 [[0, true], true],507 [[-128, true], true],508 [[true, true], true],509 [[false, true], true],510 ["z", true],511 ["a", true],512 [Buffer.from([255]), true],513 [Buffer.from([0]), true],514 [new Date(1000), true],515 [new Date(-1000), true],516 [Infinity, true],517 [Math.PI, true],518 [Math.E, true],519 [0, true],520 [-Math.E, true],521 [-Math.PI, true],522 [-Infinity, true],523 [Infinity, true],524 [0, true],525 [-Infinity, true],526 [18446744073709551615n, true],527 [0n, true],528 [9223372036854775807n, true],529 [0n, true],530 [-9223372036854775808n, true],531 [4294967295, true],532 [0, true],533 [2147483647, true],534 [0, true],535 [-2147483648, true],536 [65535, true],537 [0, true],538 [32767, true],539 [0, true],540 [-32768, true],541 [255, true],542 [0, true],543 [127, true],544 [0, true],545 [-128, true],546 [true, true],547 [false, true],548 ]);549 });550 });551 });...

Full Screen

Full Screen

Transaction-test.js

Source:Transaction-test.js Github

copy

Full Screen

1/**2 * Copyright 2013-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 *9 * @emails react-core10 */11'use strict';12var Transaction;13var INIT_ERRORED = 'initErrored'; // Just a dummy value to check for.14describe('Transaction', () => {15 beforeEach(() => {16 jest.resetModules();17 Transaction = require('Transaction');18 });19 /**20 * We should not invoke closers for inits that failed. We should pass init21 * return values to closers when those inits are successful. We should not22 * invoke the actual method when any of the initializers fail.23 */24 it('should invoke closers with/only-with init returns', () => {25 var throwInInit = function() {26 throw new Error('close[0] should receive Transaction.OBSERVED_ERROR');27 };28 var performSideEffect;29 var dontPerformThis = function() {30 performSideEffect = 'This should never be set to this';31 };32 /**33 * New test Transaction subclass.34 */35 var TestTransaction = function() {36 this.reinitializeTransaction();37 this.firstCloseParam = INIT_ERRORED; // WON'T be set to something else38 this.secondCloseParam = INIT_ERRORED; // WILL be set to something else39 this.lastCloseParam = INIT_ERRORED; // WON'T be set to something else40 };41 Object.assign(TestTransaction.prototype, Transaction);42 TestTransaction.prototype.getTransactionWrappers = function() {43 return [44 {45 initialize: throwInInit,46 close: function(initResult) {47 this.firstCloseParam = initResult;48 },49 },50 {51 initialize: function() {52 return 'asdf';53 },54 close: function(initResult) {55 this.secondCloseParam = initResult;56 },57 },58 {59 initialize: throwInInit,60 close: function(initResult) {61 this.lastCloseParam = initResult;62 },63 },64 ];65 };66 var transaction = new TestTransaction();67 expect(function() {68 transaction.perform(dontPerformThis);69 }).toThrow();70 expect(performSideEffect).toBe(undefined);71 expect(transaction.firstCloseParam).toBe(INIT_ERRORED);72 expect(transaction.secondCloseParam).toBe('asdf');73 expect(transaction.lastCloseParam).toBe(INIT_ERRORED);74 expect(transaction.isInTransaction()).toBe(false);75 });76 it('should invoke closers and wrapped method when inits success', () => {77 var performSideEffect;78 /**79 * New test Transaction subclass.80 */81 var TestTransaction = function() {82 this.reinitializeTransaction();83 this.firstCloseParam = INIT_ERRORED; // WILL be set to something else84 this.secondCloseParam = INIT_ERRORED; // WILL be set to something else85 this.lastCloseParam = INIT_ERRORED; // WILL be set to something else86 };87 Object.assign(TestTransaction.prototype, Transaction);88 TestTransaction.prototype.getTransactionWrappers = function() {89 return [90 {91 initialize: function() {92 return 'firstResult';93 },94 close: function(initResult) {95 this.firstCloseParam = initResult;96 },97 },98 {99 initialize: function() {100 return 'secondResult';101 },102 close: function(initResult) {103 this.secondCloseParam = initResult;104 },105 },106 {107 initialize: function() {108 return 'thirdResult';109 },110 close: function(initResult) {111 this.lastCloseParam = initResult;112 },113 },114 ];115 };116 var transaction = new TestTransaction();117 transaction.perform(function() {118 performSideEffect = 'SIDE_EFFECT';119 });120 expect(performSideEffect).toBe('SIDE_EFFECT');121 expect(transaction.firstCloseParam).toBe('firstResult');122 expect(transaction.secondCloseParam).toBe('secondResult');123 expect(transaction.lastCloseParam).toBe('thirdResult');124 expect(transaction.isInTransaction()).toBe(false);125 });126 /**127 * When the operation throws, the transaction should throw, but all of the128 * error-free closers should execute gracefully without issue. If a closer129 * throws an error, the transaction should prefer to throw the error130 * encountered earlier in the operation.131 */132 it('should throw when wrapped operation throws', () => {133 var performSideEffect;134 /**135 * New test Transaction subclass.136 */137 var TestTransaction = function() {138 this.reinitializeTransaction();139 this.firstCloseParam = INIT_ERRORED; // WILL be set to something else140 this.secondCloseParam = INIT_ERRORED; // WILL be set to something else141 this.lastCloseParam = INIT_ERRORED; // WILL be set to something else142 };143 Object.assign(TestTransaction.prototype, Transaction);144 // Now, none of the close/inits throw, but the operation we wrap will throw.145 TestTransaction.prototype.getTransactionWrappers = function() {146 return [147 {148 initialize: function() {149 return 'firstResult';150 },151 close: function(initResult) {152 this.firstCloseParam = initResult;153 },154 },155 {156 initialize: function() {157 return 'secondResult';158 },159 close: function(initResult) {160 this.secondCloseParam = initResult;161 },162 },163 {164 initialize: function() {165 return 'thirdResult';166 },167 close: function(initResult) {168 this.lastCloseParam = initResult;169 },170 },171 {172 initialize: function() {173 return 'fourthResult';174 },175 close: function(initResult) {176 throw new Error('The transaction should throw a TypeError.');177 },178 },179 ];180 };181 var transaction = new TestTransaction();182 expect(function() {183 var isTypeError = false;184 try {185 transaction.perform(function() {186 throw new TypeError('Thrown in main wrapped operation');187 });188 } catch (err) {189 isTypeError = (err instanceof TypeError);190 }191 return isTypeError;192 }()).toBe(true);193 expect(performSideEffect).toBe(undefined);194 expect(transaction.firstCloseParam).toBe('firstResult');195 expect(transaction.secondCloseParam).toBe('secondResult');196 expect(transaction.lastCloseParam).toBe('thirdResult');197 expect(transaction.isInTransaction()).toBe(false);198 });199 it('should throw errors in transaction close', () => {200 var TestTransaction = function() {201 this.reinitializeTransaction();202 };203 Object.assign(TestTransaction.prototype, Transaction);204 var exceptionMsg = 'This exception should throw.';205 TestTransaction.prototype.getTransactionWrappers = function() {206 return [207 {208 close: function(initResult) {209 throw new Error(exceptionMsg);210 },211 },212 ];213 };214 var transaction = new TestTransaction();215 expect(function() {216 transaction.perform(function() {});217 }).toThrowError(exceptionMsg);218 expect(transaction.isInTransaction()).toBe(false);219 });220 it('should allow nesting of transactions', () => {221 var performSideEffect;222 var nestedPerformSideEffect;223 /**224 * New test Transaction subclass.225 */226 var TestTransaction = function() {227 this.reinitializeTransaction();228 this.firstCloseParam = INIT_ERRORED; // WILL be set to something else229 };230 Object.assign(TestTransaction.prototype, Transaction);231 TestTransaction.prototype.getTransactionWrappers = function() {232 return [233 {234 initialize: function() {235 return 'firstResult';236 },237 close: function(initResult) {238 this.firstCloseParam = initResult;239 },240 },241 {242 initialize: function() {243 this.nestedTransaction = new NestedTransaction();244 },245 close: function() {246 // Test performing a transaction in another transaction's close()247 this.nestedTransaction.perform(function() {248 nestedPerformSideEffect = 'NESTED_SIDE_EFFECT';249 });250 },251 },252 ];253 };254 var NestedTransaction = function() {255 this.reinitializeTransaction();256 };257 Object.assign(NestedTransaction.prototype, Transaction);258 NestedTransaction.prototype.getTransactionWrappers = function() {259 return [260 {261 initialize: function() {262 this.hasInitializedNested = true;263 },264 close: function() {265 this.hasClosedNested = true;266 },267 },268 ];269 };270 var transaction = new TestTransaction();271 transaction.perform(function() {272 performSideEffect = 'SIDE_EFFECT';273 });274 expect(performSideEffect).toBe('SIDE_EFFECT');275 expect(nestedPerformSideEffect).toBe('NESTED_SIDE_EFFECT');276 expect(transaction.firstCloseParam).toBe('firstResult');277 expect(transaction.isInTransaction()).toBe(false);278 expect(transaction.nestedTransaction.hasClosedNested).toBe(true);279 expect(transaction.nestedTransaction.hasInitializedNested).toBe(true);280 expect(transaction.nestedTransaction.isInTransaction()).toBe(false);281 });...

Full Screen

Full Screen

stPrime_transfer.js

Source:stPrime_transfer.js Github

copy

Full Screen

1'use strict';2const rootPrefix = '../..',3 transactionLogConst = require(rootPrefix + '/lib/global_constant/transaction_log'),4 responseHelper = require(rootPrefix + '/lib/formatter/response'),5 logger = require(rootPrefix + '/lib/logger/custom_console_logger'),6 transactionMetaConstants = require(rootPrefix + '/lib/global_constant/transaction_meta.js'),7 TransactionMetaModel = require(rootPrefix + '/app/models/transaction_meta'),8 InstanceComposer = require(rootPrefix + '/instance_composer');9require(rootPrefix + '/lib/providers/platform');10require(rootPrefix + '/lib/cache_multi_management/transaction_log');11require(rootPrefix + '/app/models/transaction_log');12const TransferSTPrimeKlass = function(params) {13 const oThis = this;14 oThis.transactionUuid = params.transaction_uuid;15 oThis.clientId = params.client_id;16 oThis.transactionLogId = params.transaction_log_id;17};18TransferSTPrimeKlass.prototype = {19 /**20 * Perform21 *22 * @return {promise<result>}23 */24 perform: function() {25 const oThis = this;26 return oThis.asyncPerform().catch(function(error) {27 logger.error(`${__filename}::perform::catch`);28 logger.error(error);29 if (responseHelper.isCustomResult(error)) {30 return error;31 } else {32 return responseHelper.error({33 internal_error_identifier: 's_t_stpt_1',34 api_error_identifier: 'unhandled_catch_response',35 debug_options: {}36 });37 }38 });39 },40 asyncPerform: async function() {41 const oThis = this,42 transactionLogModel = oThis.ic().getTransactionLogModel(),43 transactionLogCache = oThis.ic().getTransactionLogCache(),44 configStrategy = oThis.ic().configStrategy;45 let transactionFetchResponse = await new transactionLogCache({46 uuids: [oThis.transactionUuid],47 client_id: oThis.clientId48 }).fetch();49 // check if the transaction log uuid is same as that passed in the params, otherwise error out50 if (transactionFetchResponse.isFailure()) {51 return Promise.reject(52 responseHelper.error({53 internal_error_identifier: 's_t_et_21',54 api_error_identifier: 'something_went_wrong',55 debug_options: {}56 })57 );58 }59 let transactionLog = transactionFetchResponse.data[oThis.transactionUuid];60 if (!transactionLog) {61 return responseHelper.error({62 internal_error_identifier: 's_t_stpt_2',63 api_error_identifier: 'transaction_log_invalid',64 debug_options: {}65 });66 }67 const transferSTPrimeInput = {68 sender_address: transactionLog.from_address,69 sender_passphrase: 'no_password',70 recipient_address: transactionLog.to_address,71 amount_in_wei: transactionLog.amount_in_wei.toString(10),72 options: { returnType: 'txHash', tag: '' }73 };74 const platformProvider = oThis.ic().getPlatformProvider(),75 openSTPlaform = platformProvider.getInstance();76 const transferSTPrimeBalanceObj = new openSTPlaform.services.transaction.transfer.simpleTokenPrime(77 transferSTPrimeInput78 );79 delete transferSTPrimeInput.sender_passphrase;80 let transferResponse = await transferSTPrimeBalanceObj.perform();81 if (transferResponse.isFailure()) {82 await oThis.updateParentTransactionLog(transactionLogConst.failedStatus, null, transferResponse.toHash());83 return Promise.reject(84 responseHelper.error({85 internal_error_identifier: 's_t_stpt_3',86 api_error_identifier: 'stp_transfer_failed',87 debug_options: {}88 })89 );90 }91 let transferTransactionHash = transferResponse.data.transaction_hash;92 // insert into transaction meta table93 await new TransactionMetaModel().insertRecord({94 transaction_hash: transferTransactionHash,95 kind: new TransactionMetaModel().invertedKinds[transactionLogConst.stpTransferTransactionType],96 client_id: transactionLog.client_id,97 chain_id: configStrategy.OST_UTILITY_CHAIN_ID,98 transaction_uuid: transactionLog.transaction_uuid,99 status: transactionMetaConstants.invertedStatuses[transactionMetaConstants.submitted]100 });101 logger.debug('stp tranafer tx hash::', transferTransactionHash);102 await oThis.updateParentTransactionLog(transactionLogConst.waitingForMiningStatus, transferTransactionHash);103 return Promise.resolve(104 responseHelper.successWithData({ input_params: transferSTPrimeInput, transaction_hash: transferTransactionHash })105 );106 },107 /**108 * Update Transaction log.109 *110 * @param statusString111 * @param transactionHash112 * @param errorData113 */114 updateParentTransactionLog: function(statusString, transactionHash, errorData) {115 const oThis = this,116 statusInt = transactionLogConst.invertedStatuses[statusString],117 transactionLogModel = oThis.ic().getTransactionLogModel();118 var dataToUpdate = { transaction_uuid: oThis.transactionUuid, status: statusInt };119 if (transactionHash) {120 dataToUpdate['transaction_hash'] = transactionHash;121 }122 if (errorData) {123 try {124 dataToUpdate['error_code'] = errorData.err.internal_id;125 } catch (error) {126 dataToUpdate['error_code'] = 's_t_stpt_4';127 }128 }129 return new transactionLogModel({130 client_id: oThis.clientId,131 shard_name: oThis.ic().configStrategy.TRANSACTION_LOG_SHARD_NAME132 }).updateItem(dataToUpdate);133 }134};135InstanceComposer.registerShadowableClass(TransferSTPrimeKlass, 'getTransferSTPrimeClass');...

Full Screen

Full Screen

transactions.ts

Source:transactions.ts Github

copy

Full Screen

1import { ReadPreference } from './read_preference';2import { MongoRuntimeError, MongoTransactionError } from './error';3import { ReadConcern, ReadConcernLike } from './read_concern';4import { WriteConcern } from './write_concern';5import type { Server } from './sdam/server';6import type { CommandOperationOptions } from './operations/command';7import type { Document } from './bson';8/** @internal */9export const TxnState = Object.freeze({10 NO_TRANSACTION: 'NO_TRANSACTION',11 STARTING_TRANSACTION: 'STARTING_TRANSACTION',12 TRANSACTION_IN_PROGRESS: 'TRANSACTION_IN_PROGRESS',13 TRANSACTION_COMMITTED: 'TRANSACTION_COMMITTED',14 TRANSACTION_COMMITTED_EMPTY: 'TRANSACTION_COMMITTED_EMPTY',15 TRANSACTION_ABORTED: 'TRANSACTION_ABORTED'16} as const);17/** @internal */18export type TxnState = typeof TxnState[keyof typeof TxnState];19const stateMachine: { [state in TxnState]: TxnState[] } = {20 [TxnState.NO_TRANSACTION]: [TxnState.NO_TRANSACTION, TxnState.STARTING_TRANSACTION],21 [TxnState.STARTING_TRANSACTION]: [22 TxnState.TRANSACTION_IN_PROGRESS,23 TxnState.TRANSACTION_COMMITTED,24 TxnState.TRANSACTION_COMMITTED_EMPTY,25 TxnState.TRANSACTION_ABORTED26 ],27 [TxnState.TRANSACTION_IN_PROGRESS]: [28 TxnState.TRANSACTION_IN_PROGRESS,29 TxnState.TRANSACTION_COMMITTED,30 TxnState.TRANSACTION_ABORTED31 ],32 [TxnState.TRANSACTION_COMMITTED]: [33 TxnState.TRANSACTION_COMMITTED,34 TxnState.TRANSACTION_COMMITTED_EMPTY,35 TxnState.STARTING_TRANSACTION,36 TxnState.NO_TRANSACTION37 ],38 [TxnState.TRANSACTION_ABORTED]: [TxnState.STARTING_TRANSACTION, TxnState.NO_TRANSACTION],39 [TxnState.TRANSACTION_COMMITTED_EMPTY]: [40 TxnState.TRANSACTION_COMMITTED_EMPTY,41 TxnState.NO_TRANSACTION42 ]43};44const ACTIVE_STATES: Set<TxnState> = new Set([45 TxnState.STARTING_TRANSACTION,46 TxnState.TRANSACTION_IN_PROGRESS47]);48const COMMITTED_STATES: Set<TxnState> = new Set([49 TxnState.TRANSACTION_COMMITTED,50 TxnState.TRANSACTION_COMMITTED_EMPTY,51 TxnState.TRANSACTION_ABORTED52]);53/**54 * Configuration options for a transaction.55 * @public56 */57export interface TransactionOptions extends CommandOperationOptions {58 // TODO(NODE-3344): These options use the proper class forms of these settings, it should accept the basic enum values too59 /** A default read concern for commands in this transaction */60 readConcern?: ReadConcernLike;61 /** A default writeConcern for commands in this transaction */62 writeConcern?: WriteConcern;63 /** A default read preference for commands in this transaction */64 readPreference?: ReadPreference;65 maxCommitTimeMS?: number;66}67/**68 * @public69 * A class maintaining state related to a server transaction. Internal Only70 */71export class Transaction {72 /** @internal */73 state: TxnState;74 options: TransactionOptions;75 /** @internal */76 _pinnedServer?: Server;77 /** @internal */78 _recoveryToken?: Document;79 /** Create a transaction @internal */80 constructor(options?: TransactionOptions) {81 options = options ?? {};82 this.state = TxnState.NO_TRANSACTION;83 this.options = {};84 const writeConcern = WriteConcern.fromOptions(options);85 if (writeConcern) {86 if (writeConcern.w === 0) {87 throw new MongoTransactionError('Transactions do not support unacknowledged write concern');88 }89 this.options.writeConcern = writeConcern;90 }91 if (options.readConcern) {92 this.options.readConcern = ReadConcern.fromOptions(options);93 }94 if (options.readPreference) {95 this.options.readPreference = ReadPreference.fromOptions(options);96 }97 if (options.maxCommitTimeMS) {98 this.options.maxTimeMS = options.maxCommitTimeMS;99 }100 // TODO: This isn't technically necessary101 this._pinnedServer = undefined;102 this._recoveryToken = undefined;103 }104 /** @internal */105 get server(): Server | undefined {106 return this._pinnedServer;107 }108 get recoveryToken(): Document | undefined {109 return this._recoveryToken;110 }111 get isPinned(): boolean {112 return !!this.server;113 }114 /** @returns Whether the transaction has started */115 get isStarting(): boolean {116 return this.state === TxnState.STARTING_TRANSACTION;117 }118 /**119 * @returns Whether this session is presently in a transaction120 */121 get isActive(): boolean {122 return ACTIVE_STATES.has(this.state);123 }124 get isCommitted(): boolean {125 return COMMITTED_STATES.has(this.state);126 }127 /**128 * Transition the transaction in the state machine129 * @internal130 * @param nextState - The new state to transition to131 */132 transition(nextState: TxnState): void {133 const nextStates = stateMachine[this.state];134 if (nextStates && nextStates.includes(nextState)) {135 this.state = nextState;136 if (137 this.state === TxnState.NO_TRANSACTION ||138 this.state === TxnState.STARTING_TRANSACTION ||139 this.state === TxnState.TRANSACTION_ABORTED140 ) {141 this.unpinServer();142 }143 return;144 }145 throw new MongoRuntimeError(146 `Attempted illegal state transition from [${this.state}] to [${nextState}]`147 );148 }149 /** @internal */150 pinServer(server: Server): void {151 if (this.isActive) {152 this._pinnedServer = server;153 }154 }155 /** @internal */156 unpinServer(): void {157 this._pinnedServer = undefined;158 }159}160export function isTransactionCommand(command: Document): boolean {161 return !!(command.commitTransaction || command.abortTransaction);...

Full Screen

Full Screen

transaction-pool.test.js

Source:transaction-pool.test.js Github

copy

Full Screen

1const TransactionPool = require('./transaction-pool');2const Transaction = require('./transaction');3const Wallet = require('./index');4const Blockchain = require('../blockchain');56describe('TransactionPool()', () => {7 let transactionPool, transaction, senderWallet;89 beforeEach(() => {10 transactionPool = new TransactionPool();11 senderWallet = new Wallet();12 transaction = new Transaction({13 senderWallet,14 recipient: 'fake-recipient',15 amount: 5016 });17 });1819 describe('setTransaction()', () => {20 it('adds a transaction', () => {21 transactionPool.setTransaction(transaction);2223 expect(transactionPool.transactionMap[transaction.id])24 .toBe(transaction);25 })26 });2728 describe('existingTransaction()', () => {29 it('returns an existing transaction given an input address', () => {30 transactionPool.setTransaction(transaction);3132 expect(33 transactionPool.existingTransaction({ inputAddress: senderWallet.publicKey })34 ).toBe(transaction);35 });36 });3738 describe('validTransactions()', () => {39 let validTransactions, errorMock;4041 beforeEach(() => {42 validTransactions = [];43 errorMock = jest.fn();44 global.console.error = errorMock;4546 for(let i=0; i<10; i++) {47 transaction = new Transaction({48 senderWallet,49 recipient: 'any-recipient',50 amount: 3051 });5253 if (i%3===0) {54 transaction.input.amount = 999999;55 } else if (i%3===1) {56 transaction.input.signature = new Wallet().sign('foo');57 } else {58 validTransactions.push(transaction);59 }6061 transactionPool.setTransaction(transaction);62 }6364 });6566 it('returns valid transactions', () => {67 expect(transactionPool.validTransactions()).toEqual(validTransactions);68 });6970 it('logs errors for the invalid transactions', () => {71 transactionPool.validTransactions();72 expect(errorMock).toHaveBeenCalled();73 });74 });7576 describe('clear()', () => {77 it('clears the transactions', () => {78 transactionPool.clear();7980 expect(transactionPool.transactionMap).toEqual({});81 });82 });8384 describe('clearBlochainTransactions()', () => {85 it('clears the pool of any existing blockchain transactions', () => {86 const blockchain = new Blockchain();87 const expectedTransactionMap = {};8889 for (let i=0; i<6; i++) {90 const transaction = new Wallet().createTransaction({91 recipient: 'foo',92 amount: 2093 });9495 transactionPool.setTransaction(transaction);9697 if (i%2===0) {98 blockchain.addBlock({ data: [transaction] });99 } else {100 expectedTransactionMap[transaction.id] = transaction;101 }102 }103104 transactionPool.clearBlockchainTransactions({ chain: blockchain.chain });105106 expect(transactionPool.transactionMap).toEqual(expectedTransactionMap);107 })108 }) ...

Full Screen

Full Screen

services.js

Source:services.js Github

copy

Full Screen

1const Transaction = require('./Model')2const { generateID, getUnixTime } = require('../../utils/services/supportServices')3const { RANDOM_STRING_FOR_CONCAT } = require('../../utils/constants/number')4const Merchant = require('../rp_merchant/Model')5const Institution = require('../rp_institution/Model')6const addUserTransaction = async ({ bill, userID = null, qrID = null, qr_id_native = null, amount, merchantID, transactionMethod, institutionID = null, billing_id_native = null, user_id_native = null, topup_method = null }) => {7 // const { error } = Transaction.validation({ user_id: userID, billing_id: bill })8 // if (error) throw new Error({ status: 400, error: error.details[0].message })9 try {10 if (merchantID) {11 var nativeMerchantID = await Merchant.findOne({ merchant_id: merchantID }).select('_id')12 } else {13 nativeMerchantID = null14 }15 if (institutionID) {16 var { _id } = await Institution.findOne({ institution_id: institutionID })17 } else {18 _id = null19 }20 let transaction = await new Transaction({21 merchant_id_native: nativeMerchantID,22 billing_id: bill,23 billing_id_native,24 user_id: userID,25 user_id_native,26 qr_id: qrID,27 qr_id_native,28 merchant_id: merchantID,29 transaction_method: transactionMethod,30 transaction_amount: amount,31 topup_method,32 transaction_id: generateID(RANDOM_STRING_FOR_CONCAT),33 institution_id: institutionID,34 institution_id_native: _id,35 isSettlement: 'N',36 created_at: getUnixTime(),37 updated_at: getUnixTime()38 })39 transaction = await transaction.save()40 return transaction41 } catch (err) {42 throw new Error(err)43 }44}45const getTransaction = async (transactionID) => {46 const transaction = await Transaction.findOne({ transaction_id: transactionID })47 if (!transaction) throw new Error('Invalid Transaction Id')48 return transaction49}50const cancelTransaction = async (transactionID) => {51 return Transaction.updateOne({ transaction_id: transactionID }, { status: 'CANCEL', updated_at: getUnixTime() })52}53const transactionStatusPendingChecker = async (transactionID) => {54 const res = await getTransaction(transactionID)55 if (res) {56 if (res.status !== 'PNDNG') throw new Error('Transaction status is not pending anymore')57 }58}59const checkerValidTransaction = async (transactionID) => {60 if (!transactionID) throw new Error('Invalid Transaction ID')61 const res = await Transaction.findOne({ transaction_id: transactionID })62 if (!res) throw new Error('Invalid Transaction ID')63}64module.exports.addUserTransaction = addUserTransaction65module.exports.getTransaction = getTransaction66module.exports.cancelTransaction = cancelTransaction67module.exports.transactionStatusPendingChecker = transactionStatusPendingChecker...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var fs = require('fs');3var client = wpt('www.webpagetest.org');4var options = {5};6client.runTest(url, options, function(err, data) {7 if (err) return console.error(err);8 console.log('Test submitted. Polling for results...');9 client.waitForTestToComplete(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log('Test completed!');12 console.log(data.data.median.firstView);13 client.getTestVideo(data.data.testId, function(err, data) {14 if (err) return console.error(err);15 fs.writeFile('video.webm', data);16 });17 });18});

Full Screen

Using AI Code Generation

copy

Full Screen

1const Web3 = require('web3');2const Tx = require('ethereumjs-tx').Transaction;3const web3 = new Web3(rpcURL);4 {5 {6 }7 },8 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var transaction = require('../transaction');2var assert = require('assert');3var t = transaction.createTransaction();4assert.equal(t.status, "created");5assert.equal(t.id, 1);6t.begin();7assert.equal(t.status, "started");8t.commit();9assert.equal(t.status, "committed");10t = transaction.createTransaction();11t.begin();12t.abort();13assert.equal(t.status, "aborted");14t = transaction.createTransaction();15t.begin();16t.commit();17t.abort();18assert.equal(t.status, "committed");19t = transaction.createTransaction();20t.begin();21t.abort();22t.commit();23assert.equal(t.status, "aborted");24t = transaction.createTransaction();25t.begin();26t.commit();27t.commit();28assert.equal(t.status, "committed");29t = transaction.createTransaction();30t.begin();31t.abort();32t.abort();33assert.equal(t.status, "aborted");34t = transaction.createTransaction();35t.begin();36t.commit();37t.begin();38assert.equal(t.status, "started");39t = transaction.createTransaction();40t.begin();41t.abort();42t.begin();43assert.equal(t.status, "started");44t = transaction.createTransaction();45t.begin();46t.begin();47assert.equal(t.status, "started");48t = transaction.createTransaction();49t.begin();50t.begin();51t.commit();52assert.equal(t.status, "started");53t = transaction.createTransaction();54t.begin();55t.begin();56t.abort();57assert.equal(t.status, "started");58t = transaction.createTransaction();59t.begin();60t.begin();61t.begin();62assert.equal(t.status, "started");63t = transaction.createTransaction();64t.begin();65t.begin();66t.begin();67t.commit();68assert.equal(t.status, "started");69t = transaction.createTransaction();70t.begin();71t.begin();72t.begin();73t.abort();74assert.equal(t.status, "started");75t = transaction.createTransaction();76t.begin();77t.begin();78t.begin();79t.begin();80assert.equal(t.status, "started");81t = transaction.createTransaction();82t.begin();83t.begin();84t.begin();85t.begin();86t.commit();87assert.equal(t.status, "started");88t = transaction.createTransaction();89t.begin();90t.begin();91t.begin();92t.begin();93t.abort();94assert.equal(t.status, "started");95t = transaction.createTransaction();96t.begin();97t.begin();98t.begin();99t.begin();100t.begin();101assert.equal(t.status, "started");102t = transaction.createTransaction();103t.begin();104t.begin();105t.begin();106t.begin();107t.begin();108t.commit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wptapi');2var client = new wpt('A.3c6a0d7e8a6c3d6f9b6c0b6a8e6f1d6e');3var testid = process.argv[2];4client.transaction(testid, function(err, data) {5 console.log(data);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const api = new wpt('A.9b9a8c8d2b6a2b6c0e6b8f6a5e7d0d5f');3 lighthouseConfig: {4 settings: {5 {6 {7 },8 },9 },10 },11 lighthouseConfig: {12 settings: {13 {14 {15 },16 },17 },18 },19 lighthouseConfig: {20 settings: {21 {22 {23 },24 },25 },26 },

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful