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
10 changed files
with
255 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
contracts/tec/contracts/src/registry/MixinTECRegistryCore.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/ITECRegistryCore.sol"; | ||
|
||
|
||
// solhint-disable no-empty-blocks | ||
contract MixinTECRegistryCore is | ||
ITECRegistryCore | ||
{ | ||
// mapping from `tecOperator` -> `tecEndpoint` | ||
mapping (address => string) internal tecEndpoints; | ||
|
||
/// @dev Called by a TEC operator to set the endpoint of their TEC. | ||
/// @param tecEndpoint endpoint of the TEC. | ||
function setTecEndpoint(string calldata tecEndpoint) external { | ||
address tecOperator = msg.sender; | ||
tecEndpoints[tecOperator] = tecEndpoint; | ||
emit TecEndpointSet(tecOperator, tecEndpoint); | ||
} | ||
|
||
/// @dev Gets the endpoint for a TEC. | ||
/// @param tecOperator operator of the TEC endpoint. | ||
function getTecEndpoint(address tecOperator) external view returns (string memory tecEndpoint) { | ||
return tecEndpoints[tecOperator]; | ||
} | ||
} |
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,33 @@ | ||
/* | ||
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 "./MixinTECRegistryCore.sol"; | ||
|
||
|
||
// solhint-disable no-empty-blocks | ||
contract TECRegistry is | ||
MixinTECRegistryCore | ||
{ | ||
constructor () | ||
public | ||
MixinTECRegistryCore() | ||
{} | ||
} |
39 changes: 39 additions & 0 deletions
39
contracts/tec/contracts/src/registry/interfaces/ITECRegistryCore.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,39 @@ | ||
/* | ||
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; | ||
|
||
|
||
// solhint-disable no-empty-blocks | ||
contract ITECRegistryCore | ||
{ | ||
/// @dev Emitted when a TEC endpoint is set. | ||
event TecEndpointSet( | ||
address tecOperator, | ||
string tecEndpoint | ||
); | ||
|
||
/// @dev Called by a TEC operator to set the endpoint of their TEC. | ||
/// @param tecEndpoint endpoint of the TEC. | ||
function setTecEndpoint(string calldata tecEndpoint) external; | ||
|
||
/// @dev Gets the endpoint for a TEC. | ||
/// @param tecOperator operator of the TEC endpoint. | ||
function getTecEndpoint(address tecOperator) external view returns (string memory tecEndpoint); | ||
} |
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 { TECRegistryTecEndpointSetEventArgs } from '../src'; | ||
|
||
import { TECRegistryWrapper } from './utils/tec_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('TEC Registry tests', () => { | ||
let tecOperator: string; | ||
const tecEndpoint = 'http://sometec.0x.org'; | ||
const nilTecEndpoint = ''; | ||
let tecRegistryWrapper: TECRegistryWrapper; | ||
// tests | ||
before(async () => { | ||
await blockchainLifecycle.startAsync(); | ||
}); | ||
after(async () => { | ||
await blockchainLifecycle.revertAsync(); | ||
}); | ||
before(async () => { | ||
// setup accounts (skip owner) | ||
const accounts = await web3Wrapper.getAvailableAddressesAsync(); | ||
[, tecOperator] = accounts; | ||
// deploy tec registry | ||
tecRegistryWrapper = new TECRegistryWrapper(provider); | ||
await tecRegistryWrapper.deployTecRegistryAsync(); | ||
}); | ||
beforeEach(async () => { | ||
await blockchainLifecycle.startAsync(); | ||
}); | ||
afterEach(async () => { | ||
await blockchainLifecycle.revertAsync(); | ||
}); | ||
describe('core', () => { | ||
it('Should successfully set a TEC endpoint', async () => { | ||
await tecRegistryWrapper.setTecEndpointAsync(tecOperator, tecEndpoint); | ||
const recordedTecEndpoint = await tecRegistryWrapper.getTecEndpointAsync(tecOperator); | ||
expect(recordedTecEndpoint).to.be.equal(tecEndpoint); | ||
}); | ||
it('Should successfully unset a TEC endpoint', async () => { | ||
// set TEC endpoint | ||
await tecRegistryWrapper.setTecEndpointAsync(tecOperator, tecEndpoint); | ||
let recordedTecEndpoint = await tecRegistryWrapper.getTecEndpointAsync(tecOperator); | ||
expect(recordedTecEndpoint).to.be.equal(tecEndpoint); | ||
// unset TEC endpoint | ||
await tecRegistryWrapper.setTecEndpointAsync(tecOperator, nilTecEndpoint); | ||
recordedTecEndpoint = await tecRegistryWrapper.getTecEndpointAsync(tecOperator); | ||
expect(recordedTecEndpoint).to.be.equal(nilTecEndpoint); | ||
}); | ||
it('Should emit an event when setting TEC endpoint', async () => { | ||
// set TEC endpoint | ||
const txReceipt = await tecRegistryWrapper.setTecEndpointAsync(tecOperator, tecEndpoint); | ||
const recordedTecEndpoint = await tecRegistryWrapper.getTecEndpointAsync(tecOperator); | ||
expect(recordedTecEndpoint).to.be.equal(tecEndpoint); | ||
// validate event | ||
expect(txReceipt.logs.length).to.be.equal(1); | ||
const log = txReceipt.logs[0] as LogWithDecodedArgs<TECRegistryTecEndpointSetEventArgs>; | ||
expect(log.args.tecOperator).to.be.equal(tecOperator); | ||
expect(log.args.tecEndpoint).to.be.equal(tecEndpoint); | ||
}); | ||
}); | ||
}); |
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,62 @@ | ||
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, TECRegistryContract } from '../../src'; | ||
|
||
export class TECRegistryWrapper { | ||
private readonly _web3Wrapper: Web3Wrapper; | ||
private readonly _provider: ZeroExProvider; | ||
private readonly _logDecoder: LogDecoder; | ||
private _tecRegistryContract?: TECRegistryContract; | ||
/** | ||
* Instanitates an ERC20Wrapper | ||
* @param provider Web3 provider to use for all JSON RPC requests | ||
* @param tecOperatorAddresses Addresses of TEC operators | ||
* @param contractOwnerAddress Desired owner of the contract | ||
* Instance of ERC20Wrapper | ||
*/ | ||
constructor(provider: ZeroExProvider) { | ||
this._web3Wrapper = new Web3Wrapper(provider); | ||
this._provider = provider; | ||
this._logDecoder = new LogDecoder(this._web3Wrapper, artifacts); | ||
} | ||
public async deployTecRegistryAsync(): Promise<TECRegistryContract> { | ||
this._tecRegistryContract = await TECRegistryContract.deployFrom0xArtifactAsync( | ||
artifacts.TECRegistry, | ||
this._provider, | ||
txDefaults, | ||
); | ||
if (_.isUndefined(this._tecRegistryContract)) { | ||
throw new Error(`Failed to deploy TEC Registry contract.`); | ||
} | ||
return this._tecRegistryContract; | ||
} | ||
public async setTecEndpointAsync( | ||
tecOperator: string, | ||
tecEndpoint: string, | ||
): Promise<TransactionReceiptWithDecodedLogs> { | ||
this._assertTECRegistryDeployed(); | ||
const txReceipt = await this._logDecoder.getTxWithDecodedLogsAsync( | ||
await (this._tecRegistryContract as TECRegistryContract).setTecEndpoint.sendTransactionAsync(tecEndpoint, { | ||
from: tecOperator, | ||
}), | ||
); | ||
return txReceipt; | ||
} | ||
public async getTecEndpointAsync(tecOperator: string): Promise<string> { | ||
this._assertTECRegistryDeployed(); | ||
const tecEndpoint = await (this._tecRegistryContract as TECRegistryContract).getTecEndpoint.callAsync( | ||
tecOperator, | ||
); | ||
return tecEndpoint; | ||
} | ||
private _assertTECRegistryDeployed(): void { | ||
if (_.isUndefined(this._tecRegistryContract)) { | ||
throw new Error( | ||
'The TEC Registry contract was not deployed through the TECRegistryWrapper. Call `eployTecRegistryAsync` to deploy.', | ||
); | ||
} | ||
} | ||
} |
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