Repository: onflow/fcl-js
Pull request #998 (2022-02-02 21:51:19)

[sdk] Rename preSendCheck and expose as voucherIntercept
### Expose `voucherIntercept` builder and resolver

- Rename `preSendCheck` to `voucherIntercept`
- Async function that receives a voucher object before sending tx
- Within this, you can call `sdk.voucherToTxId(voucher)` to get the txId 
- If an error is thrown in this, the transaction sending process will be aborted

Closes https://github.com/onflow/fcl-js/issues/984


Patch:
diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md
index c598eedf..28fbc9ff 100644
--- a/packages/sdk/CHANGELOG.md
+++ b/packages/sdk/CHANGELOG.md
@@ -1,5 +1,6 @@
 ## Unreleased
 
+- 2022-02-02 -- [@gregsantos](https://github.com/gregsantos): Rename `preSendCheck` to `voucherIntercept` and expose.
 - 2022-01-31 -- [@chasefleming](https://github.com/chasefleming): Fix SDK circular dependency in `src/block.js` file.
 
 ## 0.0.57-alpha.1 -- 2022-01-21
diff --git a/packages/sdk/readme.md b/packages/sdk/readme.md
index 0f50346f..21c124fd 100644
--- a/packages/sdk/readme.md
+++ b/packages/sdk/readme.md
@@ -356,7 +356,7 @@ Please reference the provided example project `react-simple` for example code.
 
 ### Example: Pre Checking Before Sending A Transaction
 
-As an extension, it is possible to insert a pre-check process before sending a transaction. To do this, use `sdk.preSendCheck(...)`. This argument is an arbitrary async function that receives a voucher object containing information about the transaction before it is sent. Within this, you can call `sdk.voucherToTxId(voucher)` to get the txId. Furthermore, you can call any API to record this txId before sending the transaction. If an error is thrown in this, the transaction sending process will be aborted.
+As an extension, it is possible to intercept the voucher before sending a transaction. To do this, use `sdk.voucherIntercept(...)`. This argument is an arbitrary async function that receives a voucher object containing information about the transaction before it is sent. Within this, you can call `sdk.voucherToTxId(voucher)` to get the txId. Furthermore, you can call any API to record this txId before sending the transaction. If an error is thrown in this, the transaction sending process will be aborted.
 
 ```javascript
 import * as sdk from "@onflow/sdk"
@@ -368,7 +368,7 @@ const response = await sdk.send(
       sdk.payer(sdk.authorization("01", signingFunction, 0)),
       sdk.proposer(sdk.authorization("01", signingFunction, 0, seqNum)),
       sdk.authorizations([sdk.authorization("01", signingFunction, 0)]),
-      sdk.preSendCheck(async voucher => {
+      sdk.voucherIntercept(async voucher => {
         const txId = sdk.voucherToTxId(voucher)
 
         // you can make an async to your backend to keep track of the hash
@@ -457,7 +457,7 @@ const response = await sdk.send(await sdk.pipe(await sdk.build([
   sdk.payer(sdk.authorization("01", signingFunction, 0)),
   sdk.proposer(sdk.authorization("01", signingFunction, 0)),
   sdk.authorizations([sdk.authorization("01", signingFunction, 0)]),
-  sdk.preSendCheck(async voucher => {}), // Optional
+  sdk.voucherIntercept(async voucher => {}), // Optional
 ]), [
   sdk.resolve([
     sdk.resolveArguments,
@@ -466,7 +466,7 @@ const response = await sdk.send(await sdk.pipe(await sdk.build([
     sdk.resolveProposerSequenceNumber({ node: "http://localhost:8080" }),
     sdk.resolveRefBlockId({ node: "http://localhost:8080" }),
     sdk.resolveSignatures,
-    sdk.resolvePreSendCheck, // Optional
+    sdk.resolveVoucherIntercept, // Optional
   ]),
 ]), { node: "http://localhost:8080" })
 ```
@@ -510,7 +510,7 @@ const response = await sdk.send(await sdk.pipe(await sdk.build([
   - [`sdk.limit`](./src/build/build-limit.js)
   - [`sdk.payer`](./src/build/build-payer.js)
   - [`sdk.ping`](./src/build/build-ping.js)
-  - [`sdk.preSendCheck`](./src/build/build-pre-send-check.js)
+  - [`sdk.voucherIntercept`](./src/build/build-voucher-intercept.js)
   - [`sdk.proposer`](./src/build/build-proposer.js)
   - [`sdk.ref`](./src/build/build-ref.js)
   - [`sdk.script`](./src/build/build-script.js)
@@ -522,7 +522,7 @@ const response = await sdk.send(await sdk.pipe(await sdk.build([
   - [`sdk.resolveArguments`](./src/resolve/resolve-arguments.js)
   - [`sdk.resolveCadence`](./src/resolve/resolve-cadence.js)
   - [`sdk.resolveFinalNormalization`](./src/resolve/resolve-final-normalization.js)
-  - [`sdk.resolvePreSendCheck`](./src/resolve/resolve-pre-send-check.js)
+  - [`sdk.resolveVoucherIntercept`](./src/resolve/resolve-voucher-intercept.js)
   - [`sdk.resolveProposerSequenceNumber`](./src/resolve/resolve-proposer-sequence-number.js)
   - [`sdk.resolveRefBlockId`](./src/resolve/resolve-ref-block-id.js)
   - [`sdk.resolveSignatures`](./src/resolve/resolve-signatures.js)
diff --git a/packages/sdk/src/build/build-pre-send-check.js b/packages/sdk/src/build/build-pre-send-check.js
deleted file mode 100644
index 969dda22..00000000
--- a/packages/sdk/src/build/build-pre-send-check.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import {put} from "../interaction/interaction.js"
-
-export function preSendCheck(fn) {
-  return put('ix.pre-send-check', fn)
-}
diff --git a/packages/sdk/src/build/build-voucher-intercept.js b/packages/sdk/src/build/build-voucher-intercept.js
new file mode 100644
index 00000000..ad99ba1a
--- /dev/null
+++ b/packages/sdk/src/build/build-voucher-intercept.js
@@ -0,0 +1,5 @@
+import {put} from "../interaction/interaction.js"
+
+export function voucherIntercept(fn) {
+  return put("ix.voucher-intercept", fn)
+}
diff --git a/packages/sdk/src/resolve/resolve-pre-send-check.js b/packages/sdk/src/resolve/resolve-pre-send-check.js
deleted file mode 100644
index ad6e856f..00000000
--- a/packages/sdk/src/resolve/resolve-pre-send-check.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import {get, isFn} from "../interaction/interaction.js"
-import {createSignableVoucher} from "../resolve/voucher.js"
-
-export async function resolvePreSendCheck(ix) {
-  const fn = get(ix, "ix.pre-send-check")
-  if (isFn(fn)) {
-    await fn(createSignableVoucher(ix))
-  }
-  return ix
-}
diff --git a/packages/sdk/src/resolve/resolve-voucher-intercept.js b/packages/sdk/src/resolve/resolve-voucher-intercept.js
new file mode 100644
index 00000000..7a606700
--- /dev/null
+++ b/packages/sdk/src/resolve/resolve-voucher-intercept.js
@@ -0,0 +1,10 @@
+import {get, isFn} from "../interaction/interaction.js"
+import {createSignableVoucher} from "./voucher.js"
+
+export async function resolveVoucherIntercept(ix) {
+  const fn = get(ix, "ix.voucher-intercept")
+  if (isFn(fn)) {
+    await fn(createSignableVoucher(ix))
+  }
+  return ix
+}
diff --git a/packages/sdk/src/resolve/resolve.js b/packages/sdk/src/resolve/resolve.js
index 2c4f60a1..823bcfbb 100644
--- a/packages/sdk/src/resolve/resolve.js
+++ b/packages/sdk/src/resolve/resolve.js
@@ -15,34 +15,36 @@ import {resolveAccounts} from "./resolve-accounts.js"
 import {resolveSignatures} from "./resolve-signatures.js"
 import {resolveValidators} from "./resolve-validators.js"
 import {resolveFinalNormalization} from "./resolve-final-normalization.js"
-import {resolvePreSendCheck} from "./resolve-pre-send-check.js"
+import {resolveVoucherIntercept} from "./resolve-voucher-intercept.js"
 
 const noop = v => v
-const debug = (key, fn = noop) => async ix => {
-  const take = (obj, keys = []) => {
-    if (typeof keys === "string") keys = keys.split(" ")
-    keys.reduce((acc, key) => ({...acc, [key]: obj[key]}), {})
-  }
+const debug =
+  (key, fn = noop) =>
+  async ix => {
+    const take = (obj, keys = []) => {
+      if (typeof keys === "string") keys = keys.split(" ")
+      keys.reduce((acc, key) => ({...acc, [key]: obj[key]}), {})
+    }
 
-  const accts = ix =>
-    [
-      "\nAccounts:",
-      {
-        proposer: ix.proposer,
-        authorizations: ix.authorizations,
-        payer: ix.payer,
-      },
-      "\n\nDetails:",
-      ix.accounts,
-    ].filter(Boolean)
+    const accts = ix =>
+      [
+        "\nAccounts:",
+        {
+          proposer: ix.proposer,
+          authorizations: ix.authorizations,
+          payer: ix.payer,
+        },
+        "\n\nDetails:",
+        ix.accounts,
+      ].filter(Boolean)
 
-  const log = (...msg) => {
-    console.log(`debug[${key}] ---\n`, ...msg, "\n\n\n---")
-  }
+    const log = (...msg) => {
+      console.log(`debug[${key}] ---\n`, ...msg, "\n\n\n---")
+    }
 
-  if (await config.get(`debug.${key}`)) await fn(ix, log, accts)
-  return ix
-}
+    if (await config.get(`debug.${key}`)) await fn(ix, log, accts)
+    return ix
+  }
 
 export const resolve = pipe([
   resolveCadence,
@@ -57,23 +59,27 @@ export const resolve = pipe([
   debug("signatures", (ix, log, accts) => log(...accts(ix))),
   resolveFinalNormalization,
   resolveValidators,
-  resolvePreSendCheck,
+  resolveVoucherIntercept,
   debug("resolved", (ix, log) => log(ix)),
 ])
 
 async function execFetchRef(ix) {
   if (isTransaction(ix) && ix.message.refBlock == null) {
     const node = await config().get("accessNode.api")
-    const sendFn = await config.first(
-      ["sdk.transport", "sdk.send"]
-    )
+    const sendFn = await config.first(["sdk.transport", "sdk.send"])
 
     invariant(
-      sendFn, 
+      sendFn,
       `Required value for sdk.transport is not defined in config. See: ${"https://github.com/onflow/fcl-js/blob/master/packages/sdk/CHANGELOG.md#0057-alpha1----2022-01-21"}`
     )
 
-    ix.message.refBlock = (await sendFn(build([getBlock()]), {config, response, ix: ixModule}, {node}).then(decode)).id
+    ix.message.refBlock = (
+      await sendFn(
+        build([getBlock()]),
+        {config, response, ix: ixModule},
+        {node}
+      ).then(decode)
+    ).id
   }
   return ix
 }
@@ -84,12 +90,10 @@ async function execFetchSequenceNumber(ix) {
     invariant(acct, `Transactions require a proposer`)
     if (acct.sequenceNum == null) {
       const node = await config().get("accessNode.api")
-      const sendFn = await config.first(
-        ["sdk.transport", "sdk.send"]
-      )
+      const sendFn = await config.first(["sdk.transport", "sdk.send"])
 
       invariant(
-        sendFn, 
+        sendFn,
         `Required value for sdk.transport is not defined in config. See: ${"https://github.com/onflow/fcl-js/blob/master/packages/sdk/CHANGELOG.md#0057-alpha1----2022-01-21"}`
       )
 
diff --git a/packages/sdk/src/sdk.js b/packages/sdk/src/sdk.js
index 223b1c8a..96d9bb5a 100644
--- a/packages/sdk/src/sdk.js
+++ b/packages/sdk/src/sdk.js
@@ -67,7 +67,7 @@ export {script} from "./build/build-script.js"
 export {transaction} from "./build/build-transaction.js"
 export {validator} from "./build/build-validator.js"
 export {invariant} from "./build/build-invariant.js"
-// export {preSendCheck} from "./build/build-pre-send-check.js"
+export {voucherIntercept} from "./build/build-voucher-intercept.js"
 
 // Resolvers
 export {resolveCadence} from "./resolve/resolve-cadence.js"
@@ -78,7 +78,7 @@ export {resolveAccounts} from "./resolve/resolve-accounts.js"
 export {resolveSignatures} from "./resolve/resolve-signatures.js"
 export {resolveValidators} from "./resolve/resolve-validators.js"
 export {resolveRefBlockId} from "./resolve/resolve-ref-block-id.js"
-// export {resolvePreSendCheck} from "./resolve/resolve-pre-send-check.js"
+export {resolveVoucherIntercept} from "./resolve/resolve-voucher-intercept.js"
 
 // Config
 export {config} from "./config"


Test patch:
diff --git a/packages/sdk/src/build/build-pre-send-check.test.js b/packages/sdk/src/build/build-pre-send-check.test.js
deleted file mode 100644
index 5409dccc..00000000
--- a/packages/sdk/src/build/build-pre-send-check.test.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import {interaction} from "../interaction/interaction.js"
-import {preSendCheck} from "./build-pre-send-check"
-
-describe("Build preSendCheck", () => {
-  test("Build preSendCheck", async () => {
-    const checkFunc = async () => "test func"
-
-    const ix = await preSendCheck(checkFunc)(interaction())
-
-    expect(ix.assigns["ix.pre-send-check"]).toEqual(checkFunc)
-  })
-})
diff --git a/packages/sdk/src/build/build-voucher-intercept.test.js b/packages/sdk/src/build/build-voucher-intercept.test.js
new file mode 100644
index 00000000..6e6c6cf3
--- /dev/null
+++ b/packages/sdk/src/build/build-voucher-intercept.test.js
@@ -0,0 +1,12 @@
+import {interaction} from "../interaction/interaction.js"
+import {voucherIntercept} from "./build-voucher-intercept"
+
+describe("Build voucherIntercept", () => {
+  test("Build voucherIntercept", async () => {
+    const checkFunc = async () => "test func"
+
+    const ix = await voucherIntercept(checkFunc)(interaction())
+
+    expect(ix.assigns["ix.voucher-intercept"]).toEqual(checkFunc)
+  })
+})
diff --git a/packages/sdk/src/resolve/resolve-pre-send-check.test.js b/packages/sdk/src/resolve/resolve-voucher-intercept.test.js
similarity index 76%
rename from packages/sdk/src/resolve/resolve-pre-send-check.test.js
rename to packages/sdk/src/resolve/resolve-voucher-intercept.test.js
index 3f942123..c1852f1f 100644
--- a/packages/sdk/src/resolve/resolve-pre-send-check.test.js
+++ b/packages/sdk/src/resolve/resolve-voucher-intercept.test.js
@@ -1,13 +1,13 @@
-import {resolvePreSendCheck} from "./resolve-pre-send-check.js"
+import {resolveVoucherIntercept} from "./resolve-voucher-intercept.js"
 
 test("exports function", () => {
-  expect(typeof resolvePreSendCheck).toBe("function")
+  expect(typeof resolveVoucherIntercept).toBe("function")
 })
 
-test("preSendCheck is executed", async () => {
+test("voucherIntercept is executed", async () => {
   let executed = false
 
-  const checkFunc = async (voucher) => {
+  const checkFunc = async voucher => {
     executed = true
     expect(typeof voucher).toBe("object")
   }
@@ -15,7 +15,7 @@ test("preSendCheck is executed", async () => {
   const ix = {
     tag: "TRANSACTION",
     assigns: {
-      "ix.pre-send-check": checkFunc,
+      "ix.voucher-intercept": checkFunc,
     },
     message: {
       cadence: "",
@@ -45,15 +45,15 @@ test("preSendCheck is executed", async () => {
     payer: "foo",
   }
 
-  await resolvePreSendCheck(ix)
+  await resolveVoucherIntercept(ix)
 
   expect(executed).toBe(true)
 })
 
-test("preSendCheck throws error", async () => {
+test("voucherIntercept throws error", async () => {
   let executed = false
 
-  const checkFuncThrowError = async (voucher) => {
+  const checkFuncThrowError = async voucher => {
     executed = true
     throw new Error("test error")
   }
@@ -61,7 +61,7 @@ test("preSendCheck throws error", async () => {
   const ix = {
     tag: "TRANSACTION",
     assigns: {
-      "ix.pre-send-check": checkFuncThrowError,
+      "ix.voucher-intercept": checkFuncThrowError,
     },
     message: {
       cadence: "",
@@ -91,9 +91,7 @@ test("preSendCheck throws error", async () => {
     payer: "foo",
   }
 
-  await expect(resolvePreSendCheck(ix))
-    .rejects
-    .toThrow();
+  await expect(resolveVoucherIntercept(ix)).rejects.toThrow()
 
   expect(executed).toBe(true)
 })
diff --git a/packages/transport-grpc/src/send-transaction.test.js b/packages/transport-grpc/src/send-transaction.test.js
index 7516a443..8160532b 100644
--- a/packages/transport-grpc/src/send-transaction.test.js
+++ b/packages/transport-grpc/src/send-transaction.test.js
@@ -6,97 +6,112 @@ import {proposer} from "../../sdk/src/build/build-proposer.js"
 import {payer} from "../../sdk/src/build/build-payer.js"
 import {ref} from "../../sdk/src/build/build-ref.js"
 import {authorizations} from "../../sdk/src/build/build-authorizations.js"
-import {preSendCheck} from "../../sdk/src/build/build-pre-send-check.js"
+import {voucherIntercept} from "../../sdk/src/build/build-voucher-intercept.js"
 import {voucherToTxId} from "../../sdk/src/resolve/voucher.js"
 import {resolve} from "../../sdk/src/resolve/resolve.js"
 import {response as responseADT} from "../../sdk/src/response/response.js"
 
-const jsonToUInt8Array = (json) => {
-    var str = JSON.stringify(json, null, 0);
-    var ret = new Uint8Array(str.length);
-    for (var i = 0; i < str.length; i++) {
-        ret[i] = str.charCodeAt(i);
-    }
-    return ret
-};
-
-const hexStrToUInt8Array = (hex) => {
-    return new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
-};
-
-const strToUInt8Array = (str) => {
-    var ret = new Uint8Array(str.length);
-    for (var i = 0; i < str.length; i++) {
-        ret[i] = str.charCodeAt(i);
-    }
-    return ret
-};
+const jsonToUInt8Array = json => {
+  var str = JSON.stringify(json, null, 0)
+  var ret = new Uint8Array(str.length)
+  for (var i = 0; i < str.length; i++) {
+    ret[i] = str.charCodeAt(i)
+  }
+  return ret
+}
+
+const hexStrToUInt8Array = hex => {
+  return new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)))
+}
+
+const strToUInt8Array = str => {
+  var ret = new Uint8Array(str.length)
+  for (var i = 0; i < str.length; i++) {
+    ret[i] = str.charCodeAt(i)
+  }
+  return ret
+}
 
 describe("Transaction", () => {
   test("SendTransaction", async () => {
-    const unaryMock = jest.fn();
+    const unaryMock = jest.fn()
 
     const returnedTransactionId = "a1b2c3"
 
     unaryMock.mockReturnValue({
-        getId_asU8: () => hexStrToUInt8Array("a1b2c3")
-    });
+      getId_asU8: () => hexStrToUInt8Array("a1b2c3"),
+    })
 
     const response = await sendTransaction(
-        await resolve(
-            await build([
-                transaction`cadence transaction`,
-                proposer({
-                    addr: "f8d6e0586b0a20c7",
-                    keyId: 1,
-                    sequenceNum: 123,
-                    signingFunction: () => ({ 
-                        addr: "f8d6e0586b0a20c7",
-                        keyId: 1,
-                        signature: "abc123"
-                    }),
-                    resolve: null,
-                    roles: { proposer: true, authorizer: true, payer: true, param: false },
-                }),
-                payer({
-                    addr: "f8d6e0586b0a20c7",
-                    keyId: 1,
-                    sequenceNum: 123,
-                    signingFunction: () => ({ 
-                        addr: "f8d6e0586b0a20c7",
-                        keyId: 1,
-                        signature: "abc123"
-                    }),
-                    resolve: null,
-                    roles: { proposer: true, authorizer: true, payer: true, param: false },
-                }),
-                authorizations([
-                    {
-                        addr: "f8d6e0586b0a20c7",
-                        keyId: 1,
-                        sequenceNum: 123,
-                        signingFunction: () => ({ 
-                            addr: "f8d6e0586b0a20c7",
-                            keyId: 1,
-                            signature: "abc123"
-                        }),
-                        resolve: null,
-                        roles: { proposer: true, authorizer: true, payer: true, param: false },
-                    }
-                ]),
-                ref("abc123"),
-                preSendCheck(async voucher => {
-                    voucherToTxId(voucher)
-                }),
-            ])
-        ),
-        {
-            response: responseADT
-        },
-        {
-            unary: unaryMock,
-            node: "localhost:3000"
-        }
+      await resolve(
+        await build([
+          transaction`cadence transaction`,
+          proposer({
+            addr: "f8d6e0586b0a20c7",
+            keyId: 1,
+            sequenceNum: 123,
+            signingFunction: () => ({
+              addr: "f8d6e0586b0a20c7",
+              keyId: 1,
+              signature: "abc123",
+            }),
+            resolve: null,
+            roles: {
+              proposer: true,
+              authorizer: true,
+              payer: true,
+              param: false,
+            },
+          }),
+          payer({
+            addr: "f8d6e0586b0a20c7",
+            keyId: 1,
+            sequenceNum: 123,
+            signingFunction: () => ({
+              addr: "f8d6e0586b0a20c7",
+              keyId: 1,
+              signature: "abc123",
+            }),
+            resolve: null,
+            roles: {
+              proposer: true,
+              authorizer: true,
+              payer: true,
+              param: false,
+            },
+          }),
+          authorizations([
+            {
+              addr: "f8d6e0586b0a20c7",
+              keyId: 1,
+              sequenceNum: 123,
+              signingFunction: () => ({
+                addr: "f8d6e0586b0a20c7",
+                keyId: 1,
+                signature: "abc123",
+              }),
+              resolve: null,
+              roles: {
+                proposer: true,
+                authorizer: true,
+                payer: true,
+                param: false,
+              },
+            },
+          ]),
+          ref("abc123"),
+          voucherIntercept(async voucher => {
+            voucherToTxId(voucher)
+          }),
+        ])
+      ),
+      {
+        response: responseADT,
+      },
+      {
+        unary: unaryMock,
+        node: "localhost:3000",
+      }
     )
 
     expect(unaryMock.mock.calls.length).toEqual(1)
@@ -115,5 +130,4 @@ describe("Transaction", () => {
 
     expect(response.transactionId).toBe(returnedTransactionId)
   })
-
-})
\ No newline at end of file
+})
diff --git a/packages/transport-http/src/send-transaction.test.js b/packages/transport-http/src/send-transaction.test.js
index 48e381c2..037917e7 100644
--- a/packages/transport-http/src/send-transaction.test.js
+++ b/packages/transport-http/src/send-transaction.test.js
@@ -7,75 +7,90 @@ import {ref} from "../../sdk/src/build/build-ref.js"
 import {limit} from "../../sdk/src/build/build-limit.js"
 import {authorizations} from "../../sdk/src/build/build-authorizations.js"
 
-import {preSendCheck} from "../../sdk/src/build/build-pre-send-check.js"
+import {voucherIntercept} from "../../sdk/src/build/build-voucher-intercept.js"
 import {voucherToTxId} from "../../sdk/src/resolve/voucher.js"
 import {resolve} from "../../sdk/src/resolve/resolve.js"
 import {response as responseADT} from "../../sdk/src/response/response.js"
 
 describe("Transaction", () => {
   test("SendTransaction", async () => {
-    const httpRequestMock = jest.fn();
+    const httpRequestMock = jest.fn()
 
     const returnedTransactionId = "a1b2c3"
 
-    httpRequestMock.mockReturnValue({ id: returnedTransactionId });
+    httpRequestMock.mockReturnValue({id: returnedTransactionId})
 
     const response = await sendTransaction(
-        await resolve(
-            await build([
-                transaction`cadence transaction`,
-                proposer({
-                    addr: "f8d6e0586b0a20c7",
-                    keyId: 1,
-                    sequenceNum: 123,
-                    signingFunction: () => ({ 
-                        addr: "f8d6e0586b0a20c7",
-                        keyId: 1,
-                        signature: "abc123"
-                    }),
-                    resolve: null,
-                    roles: { proposer: true, authorizer: false, payer: false, param: false },
-                }),
-                payer({
-                    addr: "f8d6e0586b0a20c7",
-                    keyId: 1,
-                    sequenceNum: 123,
-                    signingFunction: () => ({ 
-                        addr: "f8d6e0586b0a20c7",
-                        keyId: 1,
-                        signature: "abc123"
-                    }),
-                    resolve: null,
-                    roles: { proposer: false, authorizer: false, payer: true, param: false },
-                }),
-                authorizations([
-                    {
-                        addr: "f8d6e0586b0a20c7",
-                        keyId: 1,
-                        sequenceNum: 123,
-                        signingFunction: () => ({ 
-                            addr: "f8d6e0586b0a20c7",
-                            keyId: 1,
-                            signature: "abc123"
-                        }),
-                        resolve: null,
-                        roles: { proposer: false, authorizer: true, payer: false, param: false },
-                    }
-                ]),
-                ref("abc123"),
-                limit(500),
-                preSendCheck(async voucher => {
-                    voucherToTxId(voucher)
-                }),
-            ])
-        ),
-        {
-            response: responseADT
-        },
-        {
-            httpRequest: httpRequestMock,
-            node: "localhost"
-        }
+      await resolve(
+        await build([
+          transaction`cadence transaction`,
+          proposer({
+            addr: "f8d6e0586b0a20c7",
+            keyId: 1,
+            sequenceNum: 123,
+            signingFunction: () => ({
+              addr: "f8d6e0586b0a20c7",
+              keyId: 1,
+              signature: "abc123",
+            }),
+            resolve: null,
+            roles: {
+              proposer: true,
+              authorizer: false,
+              payer: false,
+              param: false,
+            },
+          }),
+          payer({
+            addr: "f8d6e0586b0a20c7",
+            keyId: 1,
+            sequenceNum: 123,
+            signingFunction: () => ({
+              addr: "f8d6e0586b0a20c7",
+              keyId: 1,
+              signature: "abc123",
+            }),
+            resolve: null,
+            roles: {
+              proposer: false,
+              authorizer: false,
+              payer: true,
+              param: false,
+            },
+          }),
+          authorizations([
+            {
+              addr: "f8d6e0586b0a20c7",
+              keyId: 1,
+              sequenceNum: 123,
+              signingFunction: () => ({
+                addr: "f8d6e0586b0a20c7",
+                keyId: 1,
+                signature: "abc123",
+              }),
+              resolve: null,
+              roles: {
+                proposer: false,
+                authorizer: true,
+                payer: false,
+                param: false,
+              },
+            },
+          ]),
+          ref("abc123"),
+          limit(500),
+          voucherIntercept(async voucher => {
+            voucherToTxId(voucher)
+          }),
+        ])
+      ),
+      {
+        response: responseADT,
+      },
+      {
+        httpRequest: httpRequestMock,
+        node: "localhost",
+      }
     )
 
     expect(httpRequestMock.mock.calls.length).toEqual(1)
@@ -87,41 +102,38 @@ describe("Transaction", () => {
     const valueSent = httpRequestMock.mock.calls[0][0]
 
     expect(valueSent).toEqual({
-        hostname: "localhost",
-        path: "/v1/transactions",
-        method: "POST",
-        body: {
-            "script": "Y2FkZW5jZSB0cmFuc2FjdGlvbg==",
-            "arguments": [],
-            "reference_block_id": "abc123",
-            "gas_limit": "500",
-            "payer": "f8d6e0586b0a20c7",
-            "proposal_key": {
-                "address": "f8d6e0586b0a20c7",
-                "key_index": "1",
-                "sequence_number": "123"
-            },
-            "authorizers": [
-                "f8d6e0586b0a20c7"
-            ],
-            "payload_signatures": [
-                {
-                    "address": "f8d6e0586b0a20c7",
-                    "key_index": "1",
-                    "signature": "q8Ej",
-                }
-            ],
-            "envelope_signatures": [
-                {
-                    "address": "f8d6e0586b0a20c7",
-                    "key_index": "1",
-                    "signature": "q8Ej"
-                }
-            ]
-        }
+      hostname: "localhost",
+      path: "/v1/transactions",
+      method: "POST",
+      body: {
+        script: "Y2FkZW5jZSB0cmFuc2FjdGlvbg==",
+        arguments: [],
+        reference_block_id: "abc123",
+        gas_limit: "500",
+        payer: "f8d6e0586b0a20c7",
+        proposal_key: {
+          address: "f8d6e0586b0a20c7",
+          key_index: "1",
+          sequence_number: "123",
+        },
+        authorizers: ["f8d6e0586b0a20c7"],
+        payload_signatures: [
+          {
+            address: "f8d6e0586b0a20c7",
+            key_index: "1",
+            signature: "q8Ej",
+          },
+        ],
+        envelope_signatures: [
+          {
+            address: "f8d6e0586b0a20c7",
+            key_index: "1",
+            signature: "q8Ej",
+          },
+        ],
+      },
     })
 
     expect(response.transactionId).toBe(returnedTransactionId)
   })
-
-})
\ No newline at end of file
+})