Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
fix except integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Jan 26, 2024
1 parent 92167b8 commit a1810be
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 84 deletions.
61 changes: 0 additions & 61 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
}
// Verify minting param
Licensing.Policy memory pol = policy(policyId);
<<<<<<< HEAD
Licensing.Framework storage fw = _framework(pol.frameworkId);
uint256 policyParamsLength = pol.paramNames.length;
bool setByLinking = _policySetups[licensorIp][policyId].setByLinking;
Expand All @@ -328,10 +327,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
policyId: policyId,
licensorIpId: licensorIp
});
=======
_verifyParams(Licensing.ParamVerifierType.Mint, pol, receiver, amount);
Licensing.License memory licenseData = Licensing.License({ policyId: policyId, licensorIpIds: licensorIpIds });
>>>>>>> main
(uint256 lId, bool isNew) = _addIdOrGetExisting(abi.encode(licenseData), _hashedLicenses, _totalLicenses);
licenseId = lId;
if (isNew) {
Expand Down Expand Up @@ -380,7 +375,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {

// Verify linking params
Licensing.Policy memory pol = policy(licenseData.policyId);
<<<<<<< HEAD
Licensing.Framework storage fw = _framework(pol.frameworkId);
uint256 policyParamsLength = pol.paramNames.length;
bool verificationOk = true;
Expand All @@ -399,10 +393,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
}
}

=======
_verifyParams(Licensing.ParamVerifierType.LinkParent, pol, holder, 1);

>>>>>>> main
// Add policy to kid
_addPolictyIdToIp(childIpId, licenseData.policyId, true);
// Set parent
Expand Down Expand Up @@ -430,7 +420,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
return _licenses[licenseId];
}

<<<<<<< HEAD
function licensorIpId(uint256 licenseId) external view returns (address) {
return _licenses[licenseId].licensorIpId;
}
Expand Down Expand Up @@ -461,60 +450,10 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
}
}
}
=======
function _update(
address from,
address to,
uint256[] memory ids,
uint256[] memory values
) internal virtual override {
// We are interested in transfers, minting and burning are checked in mintLicense and linkIpToParent respectively.

if (from != address(0) && to != address(0)) {
uint256 length = ids.length;
for (uint256 i = 0; i < length; i++) {
_verifyParams(Licensing.ParamVerifierType.Transfer, policyForLicense(ids[i]), to, values[i]);
}
>>>>>>> main
}
super._update(from, to, ids, values);
}

<<<<<<< HEAD

=======
function _verifyParams(
Licensing.ParamVerifierType pvt,
Licensing.Policy memory pol,
address holder,
uint256 amount
) internal {
Licensing.Framework storage fw = _framework(pol.frameworkId);
Licensing.Parameter[] storage params = fw.parameters[pvt];
uint256 paramsLength = params.length;
bytes[] memory values = pol.getValues(pvt);

for (uint256 i = 0; i < paramsLength; i++) {
Licensing.Parameter memory param = params[i];
// Empty bytes => use default value specified in license framework creation params.
bytes memory data = values[i].length == 0 ? param.defaultValue : values[i];
bool verificationOk = false;
if (pvt == Licensing.ParamVerifierType.Mint) {
verificationOk = param.verifier.verifyMinting(holder, amount, data);
} else if (pvt == Licensing.ParamVerifierType.LinkParent) {
verificationOk = param.verifier.verifyLinkParent(holder, data);
} else if (pvt == Licensing.ParamVerifierType.Transfer) {
verificationOk = param.verifier.verifyTransfer(holder, amount, data);
} else {
// This should never happen since getValues checks for pvt validity
revert Errors.LicenseRegistry__InvalidParamVerifierType();
}
if (!verificationOk) {
revert Errors.LicenseRegistry__ParamVerifierFailed(uint8(pvt), address(param.verifier));
}
}
}
>>>>>>> main

// TODO: tokenUri from parameters, from a metadata resolver contract
}
5 changes: 2 additions & 3 deletions test/foundry/LicenseRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ contract LicenseRegistryTest is Test {
// solhint-disable-next-line no-unused-vars
(uint256 policyId, bool isNew, uint256 indexOnIpId) = registry.addPolicyToIp(ipId1, policy);

address[] memory licensorIpIds = new address[](1);
licensorIpIds[0] = ipId1;
uint256 licenseId = registry.mintLicense(policyId, licensorIpIds, 2, licenseHolder);

uint256 licenseId = registry.mintLicense(policyId, ipId1, 2, licenseHolder);

address licenseHolder2 = address(0x102);
vm.prank(licenseHolder);
Expand Down
25 changes: 6 additions & 19 deletions test/foundry/integration/Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ contract IntegrationTest is Test {
uint256 amount
) public returns (uint256 licenseId) {
(uint256 policyId, bool isNew, uint256 indexOnIpId) = attachPolicyToIPID(ipId, policyName);
address[] memory licensorIpIds = new address[](1);
licensorIpIds[0] = ipId;
licenseId = licenseRegistry.mintLicense(policyId, licensorIpIds, amount, licensee);
licenseId = licenseRegistry.mintLicense(policyId, ipId, amount, licensee);
licenseIds[licensee][policyId] = licenseId;
}

Expand Down Expand Up @@ -269,28 +267,17 @@ contract IntegrationTest is Test {
// All trues for MockVerifier means it will always return true on condition checks
bytes[] memory byteValueTrue = new bytes[](1);
byteValueTrue[0] = abi.encode(true);

Licensing.FrameworkCreationParams memory fwAllTrue = Licensing.FrameworkCreationParams({
mintingVerifiers: new IParamVerifier[](1),
mintingDefaultValues: byteValueTrue,
linkParentVerifiers: new IParamVerifier[](1),
linkParentDefaultValues: byteValueTrue,
transferVerifiers: new IParamVerifier[](1),
transferDefaultValues: byteValueTrue,
parameters: new IParamVerifier[](1),
defaultValues: byteValueTrue,
licenseUrl: "https://very-nice-verifier-license.com"
});

fwAllTrue.mintingVerifiers[0] = mockLicenseVerifier;
fwAllTrue.linkParentVerifiers[0] = mockLicenseVerifier;
fwAllTrue.transferVerifiers[0] = mockLicenseVerifier;
fwAllTrue.parameters[0] = byteValueTrue;

Licensing.FrameworkCreationParams memory fwMintPayment = Licensing.FrameworkCreationParams({
mintingVerifiers: new IParamVerifier[](1),
mintingDefaultValues: byteValueTrue, // value here doesn't matter for MintPaymentVerifier
linkParentVerifiers: new IParamVerifier[](0),
linkParentDefaultValues: new bytes[](0),
transferVerifiers: new IParamVerifier[](0),
transferDefaultValues: new bytes[](0),
parameters: new IParamVerifier[](1),
defaultValues: byteValueTrue,
licenseUrl: "https://expensive-minting-license.com"
});

Expand Down
3 changes: 2 additions & 1 deletion test/foundry/mocks/licensing/MintPaymentVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ShortString, ShortStrings } from "@openzeppelin/contracts/utils/ShortSt

import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.sol";
import { IMintParamVerifier } from "contracts/interfaces/licensing/IMintParamVerifier.sol";
import { ShortStringOps } from "contracts/utils/ShortStringOps.sol";

contract MintPaymentVerifier is IParamVerifier, IMintParamVerifier, ERC165 {

Expand Down Expand Up @@ -51,7 +52,7 @@ contract MintPaymentVerifier is IParamVerifier, IMintParamVerifier, ERC165 {
}

function name() external pure returns (bytes32) {
return NAME.toShortString();
return ShortStringOps.stringToBytes32(NAME);
}

function nameString() external pure returns (string memory) {
Expand Down

0 comments on commit a1810be

Please sign in to comment.