github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/accounts/abi/msofod_test.go (about)

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