11import { beforeAll , describe , expect , test } from "bun:test" ;
2+ import assert from "node:assert" ;
23import type { Address } from "thirdweb" ;
34import { zeroAddress } from "viem" ;
5+ import type { ApiError } from "../../../sdk/dist/thirdweb-dev-engine.cjs" ;
46import { CONFIG } from "../config" ;
57import type { setupEngine } from "../utils/engine" ;
68import { pollTransactionStatus } from "../utils/transactions" ;
@@ -14,7 +16,7 @@ describe("Write Tests", () => {
1416 beforeAll ( async ( ) => {
1517 const { engine : _engine , backendWallet : _backendWallet } = await setup ( ) ;
1618 engine = _engine ;
17- backendWallet = _backendWallet ;
19+ backendWallet = _backendWallet as Address ;
1820
1921 const res = await engine . deploy . deployToken (
2022 CONFIG . CHAIN . id . toString ( ) ,
@@ -31,16 +33,18 @@ describe("Write Tests", () => {
3133 ) ;
3234
3335 expect ( res . result . queueId ) . toBeDefined ( ) ;
36+ assert ( res . result . queueId , "queueId must be defined" ) ;
3437 expect ( res . result . deployedAddress ) . toBeDefined ( ) ;
3538
3639 const transactionStatus = await pollTransactionStatus (
3740 engine ,
38- res . result . queueId ! ,
41+ res . result . queueId ,
3942 true ,
4043 ) ;
4144
4245 expect ( transactionStatus . minedAt ) . toBeDefined ( ) ;
43- tokenContractAddress = res . result . deployedAddress ! ;
46+ assert ( res . result . deployedAddress , "deployedAddress must be defined" ) ;
47+ tokenContractAddress = res . result . deployedAddress ;
4448 console . log ( "tokenContractAddress" , tokenContractAddress ) ;
4549 } ) ;
4650
@@ -59,7 +63,7 @@ describe("Write Tests", () => {
5963
6064 const writeTransactionStatus = await pollTransactionStatus (
6165 engine ,
62- writeRes . result . queueId ! ,
66+ writeRes . result . queueId ,
6367 true ,
6468 ) ;
6569
@@ -81,7 +85,7 @@ describe("Write Tests", () => {
8185
8286 const writeTransactionStatus = await pollTransactionStatus (
8387 engine ,
84- writeRes . result . queueId ! ,
88+ writeRes . result . queueId ,
8589 true ,
8690 ) ;
8791
@@ -107,7 +111,7 @@ describe("Write Tests", () => {
107111 name : "setContractURI" ,
108112 stateMutability : "nonpayable" ,
109113 type : "function" ,
110- // outputs: [],
114+ outputs : [ ] ,
111115 } ,
112116 ] ,
113117 } ,
@@ -117,14 +121,49 @@ describe("Write Tests", () => {
117121
118122 const writeTransactionStatus = await pollTransactionStatus (
119123 engine ,
120- writeRes . result . queueId ! ,
124+ writeRes . result . queueId ,
121125 true ,
122126 ) ;
123127
124128 expect ( writeTransactionStatus . minedAt ) . toBeDefined ( ) ;
125129 } ) ;
126130
127- test . only ( "Should throw error if function name is not found" , async ( ) => {
131+ test ( "Write to a contract with non-standard abi" , async ( ) => {
132+ const writeRes = await engine . contract . write (
133+ CONFIG . CHAIN . id . toString ( ) ,
134+ tokenContractAddress ,
135+ backendWallet ,
136+ {
137+ functionName : "setContractURI" ,
138+ args : [ "https://abi-test.com" ] ,
139+ abi : [
140+ {
141+ inputs : [
142+ {
143+ name : "uri" ,
144+ type : "string" ,
145+ } ,
146+ ] ,
147+ name : "setContractURI" ,
148+ stateMutability : "nonpayable" ,
149+ type : "function" ,
150+ } ,
151+ ] ,
152+ } ,
153+ ) ;
154+
155+ expect ( writeRes . result . queueId ) . toBeDefined ( ) ;
156+
157+ const writeTransactionStatus = await pollTransactionStatus (
158+ engine ,
159+ writeRes . result . queueId ,
160+ true ,
161+ ) ;
162+
163+ expect ( writeTransactionStatus . minedAt ) . toBeDefined ( ) ;
164+ } ) ;
165+
166+ test ( "Should throw error if function name is not found" , async ( ) => {
128167 try {
129168 await engine . contract . write (
130169 CONFIG . CHAIN . id . toString ( ) ,
@@ -135,8 +174,8 @@ describe("Write Tests", () => {
135174 args : [ "" ] ,
136175 } ,
137176 ) ;
138- } catch ( e : any ) {
139- expect ( e . message ) . toBe (
177+ } catch ( e ) {
178+ expect ( ( e as ApiError ) . body ?. error ? .message ) . toBe (
140179 `could not find function with name "nonExistentFunction" in abi` ,
141180 ) ;
142181 }
0 commit comments