Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

defaultSender seems to override explicit address decleration #25

Open
crazyrabbitLTC opened this issue Nov 23, 2019 · 5 comments
Open
Labels
bug Something isn't working

Comments

@crazyrabbitLTC
Copy link
Contributor

Expected Behavior:

When creating a new instance of a contract:

const {accounts, contract, defaultSender} = require("@openzeppelin/test-environment")
const [myAddress] = accounts;
let instance = await myContract.new({from: myAddress})

I would expect that my instance has been created from myAddress, however it is still created by defaultSender.

Desired behavior:

I would expect that if I provide an address from which to create a contract, it would create the contract with my provided address.

@nventuro nventuro added the bug Something isn't working label Nov 24, 2019
@nventuro
Copy link
Contributor

Hello @crazyrabbitLTC, thanks for the report!

I made a simple project to test this but was unable to reproduce the bug. Could you share more details of your setup?

This is what I tried:

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor() public {
        _mint(msg.sender, 100);
    }
}
const { accounts, defaultSender, contract, web3 } = require('@openzeppelin/test-environment');
const [ owner, other ] = accounts;

const MyToken = contract.fromArtifact('MyToken');

describe('MyToken', () => {
  beforeEach(async () => {
    this.token = await MyToken.new({ from: owner });
  });

  it('balance is ok', async () => {
    const defaultSenderBalance = await this.token.balanceOf(defaultSender);
    const ownerBalance = await this.token.balanceOf(owner);
    const otherBalance = await this.token.balanceOf(other);

    console.log(`defaultSenderBalance: ${defaultSenderBalance}`);
    console.log(`ownerBalance: ${ownerBalance}`);
    console.log(`otherBalance: ${otherBalance}`);

    console.log(`defaultSender address: ${defaultSender}`);
    console.log(`owner address: ${owner}`);
    console.log(`deployer address: ${(await web3.eth.getTransaction(this.token.transactionHash)).from}`);
  });
});

The previous script outputs owner having 100 tokens and the other two accounts having nothing, as well as owner being the sender of the deployment tx:

defaultSenderBalance: 0
ownerBalance: 100
otherBalance: 0
defaultSender address: 0x29E39E8A740Ef03022F6E0a21A966BBDfA4867e7
owner address: 0xF373cC5928696bb45c1a730C171245Cfa7dE5C0B
deployer address: 0xF373cC5928696bb45c1a730C171245Cfa7dE5C0B

@crazyrabbitLTC
Copy link
Contributor Author

Hmm, that is strange. I'm AF(real computer) at the moment, but I'll get back to you on reproducing the bug. It came up for me when using Ownable from the OZ contracts library. In that case, it turned out that my contract's owner was being set to the default account, despite sending in a from: someAccount. But I'll have another look!

@ppoliani
Copy link

I had the exact same issue when using a custom Initializable contract.

@nventuro
Copy link
Contributor

@ppoliani thanks for the report! Could you share more information about your setup? We were unable to reproduce the original error.

@leekaimun
Copy link

I had the exact same issue when using a custom Initializable contract.

I would assume that your contract is an upgradable contract that is Ownable. If that is the case, you would need to initialize the ownership after deploying it in the test environment.

  beforeEach(async () => {
    this.token = await MyToken.new({ from: owner });
    await this.token.initialize(owner);
  });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants