github.com/codingfuture/orig-energi3@v0.8.4/accounts/abi/method_test.go (about)

     1  // Copyright 2018 The Energi Core Authors
     2  // Copyright 2018 The go-ethereum Authors
     3  // This file is part of the Energi Core library.
     4  //
     5  // The Energi Core library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The Energi Core library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package abi
    19  
    20  import (
    21  	"strings"
    22  	"testing"
    23  )
    24  
    25  const methoddata = `
    26  [
    27  	{ "type" : "function", "name" : "balance", "constant" : true },
    28  	{ "type" : "function", "name" : "send", "constant" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] },
    29  	{ "type" : "function", "name" : "transfer", "constant" : false, "inputs" : [ { "name" : "from", "type" : "address" }, { "name" : "to", "type" : "address" }, { "name" : "value", "type" : "uint256" } ], "outputs" : [ { "name" : "success", "type" : "bool" } ]  }
    30  ]`
    31  
    32  func TestMethodString(t *testing.T) {
    33  	var table = []struct {
    34  		method      string
    35  		expectation string
    36  	}{
    37  		{
    38  			method:      "balance",
    39  			expectation: "function balance() constant returns()",
    40  		},
    41  		{
    42  			method:      "send",
    43  			expectation: "function send(uint256 amount) returns()",
    44  		},
    45  		{
    46  			method:      "transfer",
    47  			expectation: "function transfer(address from, address to, uint256 value) returns(bool success)",
    48  		},
    49  	}
    50  
    51  	abi, err := JSON(strings.NewReader(methoddata))
    52  	if err != nil {
    53  		t.Fatal(err)
    54  	}
    55  
    56  	for _, test := range table {
    57  		got := abi.Methods[test.method].String()
    58  		if got != test.expectation {
    59  			t.Errorf("expected string to be %s, got %s", test.expectation, got)
    60  		}
    61  	}
    62  }