Skip to content

Commit

Permalink
Lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
quent043 committed Apr 9, 2024
1 parent 8006968 commit c2f5960
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 69 deletions.
19 changes: 13 additions & 6 deletions contracts/TalentLayerIdUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ import {TalentLayerID} from "./TalentLayerID.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

contract TalentLayerIdUtils is IERC721Receiver {

// =========================== Mappings & Variables ==============================

/**
* @notice Instance of TalentLayerID.sol
*/
TalentLayerID public talentLayerIdContract;


// =========================== Initializers ==============================

constructor(address _talentLayerIDAddress){
constructor(address _talentLayerIDAddress) {
talentLayerIdContract = TalentLayerID(_talentLayerIDAddress);
}

// =========================== User functions ==============================

function mintDelegateAndTransfer(address _to, address _delegateAddress, uint256 _platformId, string calldata _handle) external payable {
function mintDelegateAndTransfer(
address _to,
address _delegateAddress,
uint256 _platformId,
string calldata _handle
) external payable {
// Mint TLID token
uint256 tokenId = talentLayerIdContract.mint{value: msg.value}(_platformId, _handle);
// Add address as delegate
Expand All @@ -33,8 +36,12 @@ contract TalentLayerIdUtils is IERC721Receiver {

// =========================== Overrides ==============================

function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external pure override returns (bytes4) {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external pure override returns (bytes4) {
return this.onERC721Received.selector;
}

}
6 changes: 1 addition & 5 deletions contracts/TalentLayerPlatformID.sol
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,7 @@ contract TalentLayerPlatformID is ERC721Upgradeable, AccessControlUpgradeable, U
* @dev Implementation of the {ERC721Upgradeable-transferFrom} function.
* @notice Only one Id allowed per account.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override {
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
require(balanceOf(to) == 0, "Recipient already has a Platform ID");
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");

Expand Down
22 changes: 13 additions & 9 deletions scripts/tasks/deploy/deploy-talent-layer-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {formatEther} from 'ethers/lib/utils'
import {task} from 'hardhat/config'
import {DeploymentProperty, getDeploymentProperty, setDeploymentProperty} from '../../../.deployment/deploymentManager'
import {verifyAddress} from './utils'
import { formatEther } from 'ethers/lib/utils'
import { task } from 'hardhat/config'
import {
DeploymentProperty,
getDeploymentProperty,
setDeploymentProperty,
} from '../../../.deployment/deploymentManager'
import { verifyAddress } from './utils'

/**
* @notice Task created only for test purposes of the upgradable process
Expand All @@ -26,14 +30,14 @@ task('deploy-talent-layer-utils', 'Deploy utils contract')
await run('compile')

const talentLayerID = await ethers.getContractAt(
'TalentLayerID',
getDeploymentProperty(network.name, DeploymentProperty.TalentLayerID),
'TalentLayerID',
getDeploymentProperty(network.name, DeploymentProperty.TalentLayerID),
)

console.log('Deploying TalentLayerIdUtils...');
console.log('Deploying TalentLayerIdUtils...')

const TalentLayerIdUtils = await ethers.getContractFactory("TalentLayerIdUtils");
const talentLayerIdUtils = await TalentLayerIdUtils.deploy(talentLayerID.address);
const TalentLayerIdUtils = await ethers.getContractFactory('TalentLayerIdUtils')
const talentLayerIdUtils = await TalentLayerIdUtils.deploy(talentLayerID.address)

await talentLayerIdUtils.deployTransaction.wait(1)

Expand Down
4 changes: 2 additions & 2 deletions test/batch/fullWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe('TalentLayer protocol global testing', function () {
})

it('Grace can not transfer her platform ID to someone who already owns one', async function () {
const gracePlatformId = await talentLayerPlatformID.ids(grace.address);
const gracePlatformId = await talentLayerPlatformID.ids(grace.address)
expect(
talentLayerPlatformID
.connect(grace)
Expand All @@ -342,7 +342,7 @@ describe('TalentLayer protocol global testing', function () {
})

it('Grace can transfer her platform ID to someone who does not own one', async function () {
const gracePlatformId = await talentLayerPlatformID.ids(grace.address);
const gracePlatformId = await talentLayerPlatformID.ids(grace.address)
expect(
await talentLayerPlatformID
.connect(grace)
Expand Down
93 changes: 46 additions & 47 deletions test/batch/talentLayerIdUtils.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers'
import {ethers} from 'hardhat'
import {expect} from 'chai'
import {TalentLayerID, TalentLayerIdUtils, TalentLayerPlatformID,} from '../../typechain-types'
import {MintStatus,} from '../utils/constant'
import {deploy} from '../utils/deploy'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { ethers } from 'hardhat'
import { expect } from 'chai'
import { TalentLayerID, TalentLayerIdUtils, TalentLayerPlatformID } from '../../typechain-types'
import { MintStatus } from '../utils/constant'
import { deploy } from '../utils/deploy'

/**
* Deploys contract and sets up the context for TalentLayerIdUtils tests.
* @returns the deployed contracts
*/
async function deployAndSetup(
): Promise<[TalentLayerPlatformID, TalentLayerID, TalentLayerIdUtils]> {
async function deployAndSetup(): Promise<
[TalentLayerPlatformID, TalentLayerID, TalentLayerIdUtils]
> {
const [deployer, alice, backendDelegate, platformOwner] = await ethers.getSigners()
const [
talentLayerID,
talentLayerPlatformID,
] = await deploy(false)
const [talentLayerID, talentLayerPlatformID] = await deploy(false)

// Deploy TalentLayerIdUtils contract with the address of TalentLayerID
const TalentLayerIdUtils = await ethers.getContractFactory("TalentLayerIdUtils");
const talentLayerIdUtils = await TalentLayerIdUtils.deploy(talentLayerID.address);

const TalentLayerIdUtils = await ethers.getContractFactory('TalentLayerIdUtils')
const talentLayerIdUtils = await TalentLayerIdUtils.deploy(talentLayerID.address)

// Grant Platform Id Mint role to Deployer and Bob
const mintRole = await talentLayerPlatformID.MINT_ROLE()
Expand All @@ -31,55 +28,57 @@ async function deployAndSetup(
await talentLayerPlatformID.connect(deployer).whitelistUser(deployer.address)
await talentLayerPlatformID.connect(deployer).mintForAddress(platformName, platformOwner.address)


// Disable whitelist for reserved handles
await talentLayerID.connect(deployer).updateMintStatus(MintStatus.PUBLIC)

// Update mint fee
await talentLayerID.connect(deployer).updateMintFee(ethers.utils.parseEther("0.01"))
// Update mint fee
await talentLayerID.connect(deployer).updateMintFee(ethers.utils.parseEther('0.01'))

return [talentLayerPlatformID, talentLayerID, talentLayerIdUtils];
return [talentLayerPlatformID, talentLayerID, talentLayerIdUtils]
}


describe('TalentLayerIdUtils', function () {
let alice: SignerWithAddress,
backendDelegate: SignerWithAddress,
platformOwner: SignerWithAddress,
talentLayerPlatformID: TalentLayerPlatformID,
talentLayerId: TalentLayerID,
talentLayerIdUtils: TalentLayerIdUtils;
talentLayerIdUtils: TalentLayerIdUtils

const platformId = 1

before(async function () {
;[, alice, backendDelegate, platformOwner] = await ethers.getSigners()
;[talentLayerPlatformID, talentLayerId, talentLayerIdUtils] =
await deployAndSetup()
;[talentLayerPlatformID, talentLayerId, talentLayerIdUtils] = await deployAndSetup()
})

it('mintDelegateAndTransfer', async function () {
const handle = "pipou";
const mintFee = await talentLayerId.getHandlePrice(handle);

await expect(
talentLayerIdUtils.connect(backendDelegate).mintDelegateAndTransfer(alice.address, backendDelegate.address, platformId, 'pip')
).to.be.reverted

await talentLayerIdUtils.connect(backendDelegate).mintDelegateAndTransfer(alice.address, backendDelegate.address, platformId, handle, { value: mintFee })

// Assert that the token balance of alice is 1
const aliceBalance = await talentLayerId.balanceOf(alice.address)
expect(aliceBalance).to.equal(1)

// Assert that backendDelegate is delegate of alice
const aliceTokenId = await talentLayerId.ids(alice.address)
const aliceDelegate = await talentLayerId.isDelegate(aliceTokenId, backendDelegate.address)
expect(aliceDelegate).to.equal(true)

// Assert backend delegate balance is 0
const backendDelegateBalance = await talentLayerId.balanceOf(backendDelegate.address)
expect(backendDelegateBalance).to.equal(0)

})
it('mintDelegateAndTransfer', async function () {
const handle = 'pipou'
const mintFee = await talentLayerId.getHandlePrice(handle)

await expect(
talentLayerIdUtils
.connect(backendDelegate)
.mintDelegateAndTransfer(alice.address, backendDelegate.address, platformId, 'pip'),
).to.be.reverted

await talentLayerIdUtils
.connect(backendDelegate)
.mintDelegateAndTransfer(alice.address, backendDelegate.address, platformId, handle, {
value: mintFee,
})

// Assert that the token balance of alice is 1
const aliceBalance = await talentLayerId.balanceOf(alice.address)
expect(aliceBalance).to.equal(1)

// Assert that backendDelegate is delegate of alice
const aliceTokenId = await talentLayerId.ids(alice.address)
const aliceDelegate = await talentLayerId.isDelegate(aliceTokenId, backendDelegate.address)
expect(aliceDelegate).to.equal(true)

// Assert backend delegate balance is 0
const backendDelegateBalance = await talentLayerId.balanceOf(backendDelegate.address)
expect(backendDelegateBalance).to.equal(0)
})
})

0 comments on commit c2f5960

Please sign in to comment.