-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Improve argument parsing in readContract function (#749)
* refactor: Improve argument parsing in readContract function The readContract function in the src/server/routes/contract/read/read.ts file has been refactored to improve the parsing of arguments. Previously, the function split the arguments string by comma and mapped each argument. Now, the function first tries to parse the arguments as a JSON array. If successful, it uses the parsed arguments. If parsing fails, it falls back to the previous method of splitting the string. This change improves the flexibility and reliability of argument parsing in the readContract function. * refactor: Update test description for reading a contract method with struct and number params
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { beforeAll, describe, test } from "bun:test"; | ||
import { sepolia } from "thirdweb/chains"; | ||
import { expect } from "vitest"; | ||
import type { setupEngine } from "../utils/engine"; | ||
import { setup } from "./setup"; | ||
|
||
const structContractAddress = "0x83ca896ef0a66d39f0e6fcc1a93c0a09366b85b1"; | ||
const chainIdString = sepolia.id.toString(); | ||
|
||
describe("Read Tests", () => { | ||
let engine: ReturnType<typeof setupEngine>; | ||
|
||
beforeAll(async () => { | ||
const { engine: _engine, backendWallet: _backendWallet } = await setup(); | ||
engine = _engine; | ||
}); | ||
|
||
test("Read a contract method with struct and number params", async () => { | ||
const structValues = { | ||
name: "test", | ||
value: 123, | ||
}; | ||
|
||
const structString = JSON.stringify(structValues); | ||
|
||
const { result } = await engine.contract.read( | ||
"readStructAndInts", | ||
chainIdString, | ||
structContractAddress, | ||
`${structString},1,2`, | ||
); | ||
|
||
expect(result[0]).toEqual("test"); | ||
expect(result[1]).toEqual("123"); | ||
expect(result[2]).toEqual("1"); | ||
expect(result[3]).toEqual("2"); | ||
}); | ||
}); |