Address.test.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const { constants } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const AddressImpl = artifacts.require('AddressImpl');
  4. const SimpleToken = artifacts.require('SimpleToken');
  5. contract('Address', function ([_, other]) {
  6. const ALL_ONES_ADDRESS = '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF';
  7. beforeEach(async function () {
  8. this.mock = await AddressImpl.new();
  9. });
  10. describe('isContract', function () {
  11. it('should return false for account address', async function () {
  12. expect(await this.mock.isContract(other)).to.equal(false);
  13. });
  14. it('should return true for contract address', async function () {
  15. const contract = await SimpleToken.new();
  16. expect(await this.mock.isContract(contract.address)).to.equal(true);
  17. });
  18. });
  19. describe('toPayable', function () {
  20. it('should return a payable address when the account is the zero address', async function () {
  21. expect(await this.mock.toPayable(constants.ZERO_ADDRESS)).to.equal(constants.ZERO_ADDRESS);
  22. });
  23. it('should return a payable address when the account is an arbitrary address', async function () {
  24. expect(await this.mock.toPayable(other)).to.equal(other);
  25. });
  26. it('should return a payable address when the account is the all ones address', async function () {
  27. expect(await this.mock.toPayable(ALL_ONES_ADDRESS)).to.equal(ALL_ONES_ADDRESS);
  28. });
  29. });
  30. });