Skip to content

abigen doesn't support linking of contracts and libs #17010

@vincentserpoul

Description

@vincentserpoul

Hi there,

please note that this is an issue tracker reserved for bug reports and feature requests.

For general questions please use the gitter channel or the Ethereum stack exchange at https://ethereum.stackexchange.com.

System information

Geth version: 1.8.11
OS & Version: Linux
Commit hash : (if develop)

Expected behaviour

If a lib is used in a contract, it should be either a param of the Deploy function (probably the best) or the deploy should take care of the deployment of the lib first.

Actual behaviour

Contract deployment just doesn't work, no error.

Steps to reproduce the behaviour

pragma solidity ^0.4.24;

library Math {
    function add(uint a, uint b) public view returns(uint) {
        return a + b;
    }
}

contract Example {
    function add (uint c, uint d) public view returns(uint) {
        return  Math.add(c,d);
    }
}
abigen --sol=test.sol --pkg=testlink --out=./test.go
package testlink

import (
	"log"
	"math/big"
	"os"
	"testing"

	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
	"github.com/ethereum/go-ethereum/core"
	"github.com/ethereum/go-ethereum/crypto"
)


func TestExample(t *testing.T) {

	_, _, exI, err := DeployExample(testAuth, testSimBackend)
	if err != nil {
		t.Fatalf("DeployExample: %v", err)
	}
	testSimBackend.Commit()

	res, errG := exI.Add(&bind.CallOpts{}, big.NewInt(1), big.NewInt(1))
	if errG != nil {
		t.Fatalf("Add: %v", errG)
	}
	if !reflect.DeepEqual(res, big.NewInt(2)) {
		t.Errorf("Expected %d, got %d", big.NewInt(2), res)
	}
}

var testSimBackend *backends.SimulatedBackend
var testAuth *bind.TransactOpts

func TestMain(m *testing.M) {

	testAuthKey, err := crypto.GenerateKey()
	if err != nil {
		log.Fatal(err)
	}
	testAuth = bind.NewKeyedTransactor(testAuthKey)

	testAuth.GasLimit = 4000000

	alloc := make(core.GenesisAlloc)
	alloc[testAuth.From] = core.GenesisAccount{
		Balance: big.NewInt(1337000000000),
	}
	testSimBackend = backends.NewSimulatedBackend(alloc)

	retCode := m.Run()

	os.Exit(retCode)

}
go run test ./...

Add: abi: unmarshalling empty output

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions