This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
202 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
contracts/coordinator/contracts/src/registry/MixinCoordinatorRegistryCore.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2018 ZeroEx Intl. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity 0.5.3; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "./interfaces/ICoordinatorRegistryCore.sol"; | ||
|
||
|
||
// solhint-disable no-empty-blocks | ||
contract MixinCoordinatorRegistryCore is | ||
ICoordinatorRegistryCore | ||
{ | ||
// mapping from `coordinatorOperator` -> `coordinatorEndpoint` | ||
mapping (address => string) internal coordinatorEndpoints; | ||
|
||
/// @dev Called by a Coordinator operator to set the endpoint of their Coordinator. | ||
/// @param coordinatorEndpoint endpoint of the Coordinator. | ||
function setCoordinatorEndpoint(string calldata coordinatorEndpoint) external { | ||
address coordinatorOperator = msg.sender; | ||
coordinatorEndpoints[coordinatorOperator] = coordinatorEndpoint; | ||
emit CoordinatorEndpointSet(coordinatorOperator, coordinatorEndpoint); | ||
} | ||
|
||
/// @dev Gets the endpoint for a Coordinator. | ||
/// @param coordinatorOperator operator of the Coordinator endpoint. | ||
function getCoordinatorEndpoint(address coordinatorOperator) external view returns (string memory coordinatorEndpoint) { | ||
return coordinatorEndpoints[coordinatorOperator]; | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
contracts/coordinator/contracts/src/registry/MixinTECRegistryCore.sol
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange'; | ||
import { chaiSetup, provider, web3Wrapper } from '@0x/contracts-test-utils'; | ||
import { BlockchainLifecycle } from '@0x/dev-utils'; | ||
import * as chai from 'chai'; | ||
import { LogWithDecodedArgs } from 'ethereum-types'; | ||
|
||
import { CoordinatorRegistryCoordinatorEndpointSetEventArgs } from '../src'; | ||
|
||
import { CoordinatorRegistryWrapper } from './utils/coordinator_registry_wrapper'; | ||
|
||
chaiSetup.configure(); | ||
const expect = chai.expect; | ||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); | ||
web3Wrapper.abiDecoder.addABI(exchangeArtifacts.Exchange.compilerOutput.abi); | ||
// tslint:disable:no-unnecessary-type-assertion | ||
describe('Coordinator Registry tests', () => { | ||
let coordinatorOperator: string; | ||
const coordinatorEndpoint = 'http://sometec.0x.org'; | ||
const nilCoordinatorEndpoint = ''; | ||
let coordinatorRegistryWrapper: CoordinatorRegistryWrapper; | ||
// tests | ||
before(async () => { | ||
await blockchainLifecycle.startAsync(); | ||
}); | ||
after(async () => { | ||
await blockchainLifecycle.revertAsync(); | ||
}); | ||
before(async () => { | ||
// setup accounts (skip owner) | ||
const accounts = await web3Wrapper.getAvailableAddressesAsync(); | ||
[, coordinatorOperator] = accounts; | ||
// deploy coordinator registry | ||
coordinatorRegistryWrapper = new CoordinatorRegistryWrapper(provider); | ||
await coordinatorRegistryWrapper.deployCoordinatorRegistryAsync(); | ||
}); | ||
beforeEach(async () => { | ||
await blockchainLifecycle.startAsync(); | ||
}); | ||
afterEach(async () => { | ||
await blockchainLifecycle.revertAsync(); | ||
}); | ||
describe('core', () => { | ||
it('Should successfully set a Coordinator endpoint', async () => { | ||
await coordinatorRegistryWrapper.setCoordinatorEndpointAsync(coordinatorOperator, coordinatorEndpoint); | ||
const recordedCoordinatorEndpoint = await coordinatorRegistryWrapper.getCoordinatorEndpointAsync(coordinatorOperator); | ||
expect(recordedCoordinatorEndpoint).to.be.equal(coordinatorEndpoint); | ||
}); | ||
it('Should successfully unset a Coordinator endpoint', async () => { | ||
// set Coordinator endpoint | ||
await coordinatorRegistryWrapper.setCoordinatorEndpointAsync(coordinatorOperator, coordinatorEndpoint); | ||
let recordedCoordinatorEndpoint = await coordinatorRegistryWrapper.getCoordinatorEndpointAsync(coordinatorOperator); | ||
expect(recordedCoordinatorEndpoint).to.be.equal(coordinatorEndpoint); | ||
// unset Coordinator endpoint | ||
await coordinatorRegistryWrapper.setCoordinatorEndpointAsync(coordinatorOperator, nilCoordinatorEndpoint); | ||
recordedCoordinatorEndpoint = await coordinatorRegistryWrapper.getCoordinatorEndpointAsync(coordinatorOperator); | ||
expect(recordedCoordinatorEndpoint).to.be.equal(nilCoordinatorEndpoint); | ||
}); | ||
it('Should emit an event when setting Coordinator endpoint', async () => { | ||
// set Coordinator endpoint | ||
const txReceipt = await coordinatorRegistryWrapper.setCoordinatorEndpointAsync(coordinatorOperator, coordinatorEndpoint); | ||
const recordedCoordinatorEndpoint = await coordinatorRegistryWrapper.getCoordinatorEndpointAsync(coordinatorOperator); | ||
expect(recordedCoordinatorEndpoint).to.be.equal(coordinatorEndpoint); | ||
// validate event | ||
expect(txReceipt.logs.length).to.be.equal(1); | ||
const log = txReceipt.logs[0] as LogWithDecodedArgs<CoordinatorRegistryCoordinatorEndpointSetEventArgs>; | ||
expect(log.args.coordinatorOperator).to.be.equal(coordinatorOperator); | ||
expect(log.args.coordinatorEndpoint).to.be.equal(coordinatorEndpoint); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
contracts/coordinator/test/utils/coordinator_registry_wrapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { LogDecoder, txDefaults } from '@0x/contracts-test-utils'; | ||
import { Web3Wrapper } from '@0x/web3-wrapper'; | ||
import { TransactionReceiptWithDecodedLogs, ZeroExProvider } from 'ethereum-types'; | ||
import * as _ from 'lodash'; | ||
|
||
import { artifacts, CoordinatorRegistryContract } from '../../src'; | ||
|
||
export class CoordinatorRegistryWrapper { | ||
private readonly _web3Wrapper: Web3Wrapper; | ||
private readonly _provider: ZeroExProvider; | ||
private readonly _logDecoder: LogDecoder; | ||
private _coordinatorRegistryContract?: CoordinatorRegistryContract; | ||
/** | ||
* Instanitates an CoordinatorRegistryWrapper | ||
* @param provider Web3 provider to use for all JSON RPC requests | ||
* Instance of CoordinatorRegistryWrapper | ||
*/ | ||
constructor(provider: ZeroExProvider) { | ||
this._web3Wrapper = new Web3Wrapper(provider); | ||
this._provider = provider; | ||
this._logDecoder = new LogDecoder(this._web3Wrapper, artifacts); | ||
} | ||
public async deployCoordinatorRegistryAsync(): Promise<CoordinatorRegistryContract> { | ||
this._coordinatorRegistryContract = await CoordinatorRegistryContract.deployFrom0xArtifactAsync( | ||
artifacts.CoordinatorRegistry, | ||
this._provider, | ||
txDefaults, | ||
); | ||
if (_.isUndefined(this._coordinatorRegistryContract)) { | ||
throw new Error(`Failed to deploy Coordinator Registry contract.`); | ||
} | ||
return this._coordinatorRegistryContract; | ||
} | ||
public async setCoordinatorEndpointAsync( | ||
coordinatorOperator: string, | ||
coordinatorEndpoint: string, | ||
): Promise<TransactionReceiptWithDecodedLogs> { | ||
this._assertCoordinatorRegistryDeployed(); | ||
const txReceipt = await this._logDecoder.getTxWithDecodedLogsAsync( | ||
await (this._coordinatorRegistryContract as CoordinatorRegistryContract).setCoordinatorEndpoint.sendTransactionAsync(coordinatorEndpoint, { | ||
from: coordinatorOperator, | ||
}), | ||
); | ||
return txReceipt; | ||
} | ||
public async getCoordinatorEndpointAsync(coordinatorOperator: string): Promise<string> { | ||
this._assertCoordinatorRegistryDeployed(); | ||
const coordinatorEndpoint = await (this._coordinatorRegistryContract as CoordinatorRegistryContract).getCoordinatorEndpoint.callAsync( | ||
coordinatorOperator, | ||
); | ||
return coordinatorEndpoint; | ||
} | ||
private _assertCoordinatorRegistryDeployed(): void { | ||
if (_.isUndefined(this._coordinatorRegistryContract)) { | ||
throw new Error( | ||
'The Coordinator Registry contract was not deployed through the CoordinatorRegistryWrapper. Call `deployCoordinatorRegistryAsync` to deploy.', | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.