@@ -263,3 +263,108 @@ forgetest_async!(erc20_burn_success, |prj, cmd| {
263263 let total_supply: U256 = output. split_whitespace( ) . next( ) . unwrap( ) . parse( ) . unwrap( ) ;
264264 assert_eq!( total_supply, initial_supply - burn_amount) ;
265265} ) ;
266+
267+ // tests that `balance` command works correctly with --json flag
268+ forgetest_async ! ( erc20_balance_json, |prj, cmd| {
269+ let ( rpc, token) = setup_token_test( & prj, & mut cmd) . await ;
270+
271+ let output = cmd
272+ . cast_fuse( )
273+ . args( [ "--json" , "erc20" , "balance" , & token, anvil_const:: ADDR1 , "--rpc-url" , & rpc] )
274+ . assert_success( )
275+ . get_output( )
276+ . stdout_lossy( ) ;
277+
278+ let balance_str: String = serde_json:: from_str( & output) . expect( "valid json string" ) ;
279+ let balance: U256 = balance_str. parse( ) . unwrap( ) ;
280+ assert_eq!( balance, U256 :: from( 1_000_000_000_000_000_000_000u128 ) ) ;
281+ } ) ;
282+
283+ // tests that `allowance` command works correctly with --json flag
284+ forgetest_async ! ( erc20_allowance_json, |prj, cmd| {
285+ let ( rpc, token) = setup_token_test( & prj, & mut cmd) . await ;
286+
287+ // First approve some tokens
288+ let approve_amount = U256 :: from( 50_000_000_000_000_000_000u128 ) ;
289+ cmd. cast_fuse( )
290+ . args( [
291+ "erc20" ,
292+ "approve" ,
293+ & token,
294+ anvil_const:: ADDR2 ,
295+ & approve_amount. to_string( ) ,
296+ "--rpc-url" ,
297+ & rpc,
298+ "--private-key" ,
299+ anvil_const:: PK1 ,
300+ ] )
301+ . assert_success( ) ;
302+
303+ // Check allowance with JSON flag
304+ let output = cmd
305+ . cast_fuse( )
306+ . args( [
307+ "--json" ,
308+ "erc20" ,
309+ "allowance" ,
310+ & token,
311+ anvil_const:: ADDR1 ,
312+ anvil_const:: ADDR2 ,
313+ "--rpc-url" ,
314+ & rpc,
315+ ] )
316+ . assert_success( )
317+ . get_output( )
318+ . stdout_lossy( ) ;
319+
320+ let allowance_str: String = serde_json:: from_str( & output) . expect( "valid json string" ) ;
321+ let allowance: U256 = allowance_str. parse( ) . unwrap( ) ;
322+ assert_eq!( allowance, approve_amount) ;
323+ } ) ;
324+
325+ // tests that `name`, `symbol`, `decimals`, and `totalSupply` commands work correctly with --json
326+ // flag
327+ forgetest_async ! ( erc20_metadata_json, |prj, cmd| {
328+ let ( rpc, token) = setup_token_test( & prj, & mut cmd) . await ;
329+
330+ // Test name with --json
331+ let output = cmd
332+ . cast_fuse( )
333+ . args( [ "--json" , "erc20" , "name" , & token, "--rpc-url" , & rpc] )
334+ . assert_success( )
335+ . get_output( )
336+ . stdout_lossy( ) ;
337+ let name: String = serde_json:: from_str( & output) . expect( "valid json string" ) ;
338+ assert_eq!( name, "Test Token" ) ;
339+
340+ // Test symbol with --json
341+ let output = cmd
342+ . cast_fuse( )
343+ . args( [ "--json" , "erc20" , "symbol" , & token, "--rpc-url" , & rpc] )
344+ . assert_success( )
345+ . get_output( )
346+ . stdout_lossy( ) ;
347+ let symbol: String = serde_json:: from_str( & output) . expect( "valid json string" ) ;
348+ assert_eq!( symbol, "TEST" ) ;
349+
350+ // Test decimals with --json
351+ let output = cmd
352+ . cast_fuse( )
353+ . args( [ "--json" , "erc20" , "decimals" , & token, "--rpc-url" , & rpc] )
354+ . assert_success( )
355+ . get_output( )
356+ . stdout_lossy( ) ;
357+ let decimals: u8 = output. trim( ) . parse( ) . expect( "valid number" ) ;
358+ assert_eq!( decimals, 18 ) ;
359+
360+ // Test totalSupply with --json
361+ let output = cmd
362+ . cast_fuse( )
363+ . args( [ "--json" , "erc20" , "total-supply" , & token, "--rpc-url" , & rpc] )
364+ . assert_success( )
365+ . get_output( )
366+ . stdout_lossy( ) ;
367+ let total_supply_str: String = serde_json:: from_str( & output) . expect( "valid json string" ) ;
368+ let total_supply: U256 = total_supply_str. parse( ) . unwrap( ) ;
369+ assert_eq!( total_supply, U256 :: from( 1_000_000_000_000_000_000_000u128 ) ) ;
370+ } ) ;
0 commit comments