Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple wrapper for address. #1773

Merged
merged 15 commits into from
May 31, 2019
Merged

Add a simple wrapper for address. #1773

merged 15 commits into from
May 31, 2019

Conversation

Skyge
Copy link
Contributor

@Skyge Skyge commented May 25, 2019

Fix #1771.

@Skyge
Copy link
Contributor Author

Skyge commented May 26, 2019

It seems like I should also add test example at test/utils/Address.test.js.

@nventuro
Copy link
Contributor

Hello @Skyge, thank you for this contribution!

Yes, we should add this in AddresMock to test it, and have tests that:

  1. convert the zero address
  2. convert some random address
  3. convert an address of all ones (0xffff...)

All three tests should check that the input address matches the output.

@Skyge
Copy link
Contributor Author

Skyge commented May 27, 2019

Hi, @nventuro , do you mean mocks/AddressImpl.sol? because I did not fine a file named AddresMock .

@nventuro
Copy link
Contributor

Yes, my bad. Some of the mocks are inconsistently named.

@Skyge
Copy link
Contributor Author

Skyge commented May 29, 2019

@nventuro Hi, I have thought for the test case for some time, so my process will be like this: First I need a simple contract which can receive Ether, then I use an account to call a function mainly including address(A).transfer(100), because the account is not the type of payable, it will throw out an error message, then if I call another function mainly including address(A).toPayable().transfer(100), it will pass, and the balance of account A should add 100.
Same approach for testing the address(0) and address(0xffff...), so what do you think about it? Or I should take another approach to test?

@nventuro
Copy link
Contributor

I don't think you'll need to do any of that, because the payable attribute is only something the compiler uses to make developers aware of which addresses may receive funds, it's not a property of the address itself.

A function that receives an address, calls toPayable() on it and returns it, and checks that the sent and received addresses are the same should be enough.

@Skyge
Copy link
Contributor Author

Skyge commented May 30, 2019

Emmm, but if I send an address to such a function, it returns an address, how can I know it is a really address payable?

@Skyge
Copy link
Contributor Author

Skyge commented May 30, 2019

@nventuro I notice there is a constant in the openzeppelin-test-helpers: ZERO_ADDRESS, it is convenient for us to quote, but just like your advice, I also should test for the address of all ones, so is there a necessary to add such constant in the openzeppelin-test-helpers, and what should I name it better?

@nventuro
Copy link
Contributor

Emmm, but if I send an address to such a function, it returns an address, how can I know it is a really address payable?

payable is a compile-time attribute. The fact that the returned type is payable and the contract compiles is enough: all we need to actually test this function is to check that the actual value (the address) is not being accidentally modified.

I also should test for the address of all ones, so is there a necessary to add such constant in the openzeppelin-test-helpers, and what should I name it better?

I don't think this is necessary, since using this address is very uncommon: I'd just use the '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' string directly.

@Skyge
Copy link
Contributor Author

Skyge commented May 30, 2019

I don't think this is necessary, since using this address is very uncommon: I'd just use the '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' string directly.

You can see at the line 7, I define a constant: ALL_ONES_ADDRESS = '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF', it is neither 0xffffffffffffffffffffffffffffffffffffffff,nor 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.

@frangio frangio mentioned this pull request May 31, 2019
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @Skyge, thank you very much for your contribution! 🎉

@nventuro nventuro merged commit b95d7e7 into OpenZeppelin:master May 31, 2019
@Skyge
Copy link
Contributor Author

Skyge commented May 31, 2019

It is my pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address.toPayable()
2 participants