From 38d10f7ccd6567316988ce5c30d5fb6c63ae6e0f Mon Sep 17 00:00:00 2001 From: web3santa Date: Tue, 16 Apr 2024 02:08:23 +0900 Subject: [PATCH] accounts: added TestUnmarshalJSON --- accounts/abi/abi_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index bc76df0dc2..ede48ebf62 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -19,6 +19,7 @@ package abi import ( "bytes" "encoding/hex" + "encoding/json" "errors" "fmt" "math/big" @@ -1218,3 +1219,28 @@ func TestUnpackRevert(t *testing.T) { }) } } + +func TestUnmarshalJSON(t *testing.T) { + t.Parallel() + jsonData := `{"name": "Alice", "age": 30}` + + reader := bytes.NewReader([]byte(jsonData)) + + dec := json.NewDecoder(reader) + type ABI struct { + Constructor Method + Methods map[string]Method + Events map[string]Event + Errors map[string]Error + + Fallback Method // Note it's also used to represent legacy fallback before v0.6.0 + Receive Method + } + var abi ABI + + if err := dec.Decode(&abi); err != nil { + t.Fatalf("Output mismatch, want %v, got %v", err, dec) + + } + +}