2020-09-23 09:21:49 +00:00
|
|
|
import {TestEnv, makeSuite} from './helpers/make-suite';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {ZERO_ADDRESS} from '../helpers/constants';
|
2020-09-23 09:21:49 +00:00
|
|
|
import {ProtocolErrors} from '../helpers/types';
|
|
|
|
|
|
|
|
const {expect} = require('chai');
|
|
|
|
|
|
|
|
makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
|
|
|
|
it('Checks the addresses provider is added to the registry', async () => {
|
|
|
|
const {addressesProvider, registry} = testEnv;
|
|
|
|
|
|
|
|
const providers = await registry.getAddressesProvidersList();
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
expect(providers.length).to.be.equal(1, 'Invalid length of the addresses providers list');
|
|
|
|
expect(providers[0].toString()).to.be.equal(
|
|
|
|
addressesProvider.address,
|
|
|
|
' Invalid addresses provider added to the list'
|
|
|
|
);
|
2020-09-23 09:21:49 +00:00
|
|
|
});
|
|
|
|
|
2020-09-23 09:25:35 +00:00
|
|
|
it('Registers a new mock addresses provider', async () => {
|
|
|
|
const {users, registry} = testEnv;
|
|
|
|
|
|
|
|
//simulating an addresses provider using the users[1] wallet address
|
2020-10-08 13:41:48 +00:00
|
|
|
await registry.registerAddressesProvider(users[1].address, '2');
|
2020-09-23 09:25:35 +00:00
|
|
|
|
|
|
|
const providers = await registry.getAddressesProvidersList();
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
expect(providers.length).to.be.equal(2, 'Invalid length of the addresses providers list');
|
|
|
|
expect(providers[1].toString()).to.be.equal(
|
|
|
|
users[1].address,
|
|
|
|
' Invalid addresses provider added to the list'
|
|
|
|
);
|
2020-09-23 09:25:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-23 10:34:53 +00:00
|
|
|
it('Removes the mock addresses provider', async () => {
|
|
|
|
const {users, registry, addressesProvider} = testEnv;
|
2020-09-23 09:25:35 +00:00
|
|
|
|
2020-09-23 10:34:53 +00:00
|
|
|
//checking the isAddressesProviderRegistered function
|
|
|
|
const id = await registry.isAddressesProviderRegistered(users[1].address);
|
2020-10-08 13:41:48 +00:00
|
|
|
|
|
|
|
expect(id).to.be.equal('2', 'Invalid isRegistered return value');
|
|
|
|
|
2020-09-23 10:34:53 +00:00
|
|
|
await registry.unregisterAddressesProvider(users[1].address);
|
2020-09-23 09:25:35 +00:00
|
|
|
|
|
|
|
const providers = await registry.getAddressesProvidersList();
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
expect(providers.length).to.be.equal(2, 'Invalid length of the addresses providers list');
|
|
|
|
expect(providers[0].toString()).to.be.equal(
|
|
|
|
addressesProvider.address,
|
|
|
|
' Invalid addresses provider added to the list'
|
|
|
|
);
|
|
|
|
expect(providers[1].toString()).to.be.equal(ZERO_ADDRESS, ' Invalid addresses');
|
2020-09-23 09:25:35 +00:00
|
|
|
});
|
2020-09-23 15:59:43 +00:00
|
|
|
|
|
|
|
it('Tries to remove a unregistered addressesProvider', async () => {
|
|
|
|
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
|
|
|
|
|
|
|
const {users, registry} = testEnv;
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
|
|
|
|
PROVIDER_NOT_REGISTERED
|
|
|
|
);
|
2020-09-23 15:59:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Tries to remove a unregistered addressesProvider', async () => {
|
|
|
|
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
|
|
|
|
|
|
|
const {users, registry} = testEnv;
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
|
|
|
|
PROVIDER_NOT_REGISTERED
|
|
|
|
);
|
2020-09-23 15:59:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Tries to add an already added addressesProvider with a different id. Should overwrite the previous id', async () => {
|
|
|
|
const {users, registry, addressesProvider} = testEnv;
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
await registry.registerAddressesProvider(addressesProvider.address, '2');
|
2020-09-23 15:59:43 +00:00
|
|
|
|
|
|
|
const providers = await registry.getAddressesProvidersList();
|
|
|
|
|
|
|
|
const id = await registry.isAddressesProviderRegistered(addressesProvider.address);
|
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
expect(providers.length).to.be.equal(2, 'Invalid length of the addresses providers list');
|
2020-09-23 15:59:43 +00:00
|
|
|
|
2020-10-08 13:41:48 +00:00
|
|
|
expect(providers[0].toString()).to.be.equal(
|
|
|
|
addressesProvider.address,
|
|
|
|
' Invalid addresses provider added to the list'
|
|
|
|
);
|
|
|
|
expect(providers[1].toString()).to.be.equal(ZERO_ADDRESS, ' Invalid addresses');
|
2020-09-23 15:59:43 +00:00
|
|
|
});
|
2020-09-23 09:21:49 +00:00
|
|
|
});
|