Skip to content

Commit

Permalink
fix: Missing claim payment (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
codynhat committed Oct 6, 2022
1 parent b24b32f commit fe9de0c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
4 changes: 2 additions & 2 deletions contracts/registry/facets/PCOLicenseClaimerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ abstract contract IPCOLicenseClaimerFacet {
);

// Transfer initial payment
if (block.timestamp <= ds.auctionEnd) {
if (_requiredBid > 0) {
ls.paymentToken.safeTransferFrom(
msg.sender,
address(ls.beneficiary),
initialForSalePrice
_requiredBid
);
}
}
Expand Down
65 changes: 50 additions & 15 deletions test/registry/PCOLicenseClaimerFacet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,13 @@ describe("PCOLicenseClaimerFacet", async function () {

describe("claim", async () => {
it("should claim", async () => {
const { pcoLicenseClaimer, pcoLicenseParams, ethersjsSf, paymentToken } =
await Fixtures.initialized();
const {
pcoLicenseClaimer,
pcoLicenseParams,
ethersjsSf,
paymentToken,
ethx_erc20,
} = await Fixtures.initialized();
const { user } = await getNamedAccounts();

const coord = BigNumber.from(4).shl(32).or(BigNumber.from(33));
Expand All @@ -302,12 +307,14 @@ describe("PCOLicenseClaimerFacet", async function () {
const requiredBuffer = await ethersjsSf.cfaV1.contract
.connect(await ethers.getSigner(user))
.getDepositRequiredForFlowRate(paymentToken.address, contributionRate);
const approveOp = await paymentToken.approve({
const approveOp = paymentToken.approve({
receiver: pcoLicenseClaimer.address,
amount: requiredBuffer.toString(),
});
await approveOp.exec(await ethers.getSigner(user));

const nextAddress = await pcoLicenseClaimer.getNextProxyAddress(user);

const txn = await pcoLicenseClaimer
.connect(await ethers.getSigner(user))
.claim(contributionRate, forSalePrice, coord, [BigNumber.from(0)]);
Expand All @@ -317,12 +324,20 @@ describe("PCOLicenseClaimerFacet", async function () {
await expect(txn)
.to.emit(pcoLicenseClaimer, "ParcelClaimed")
.withArgs(0, user);
await expect(txn)
.to.emit(ethx_erc20, "Transfer")
.withArgs(user, nextAddress, requiredBuffer);
});

it("should claim when payment is required", async () => {
const { pcoLicenseClaimer, pcoLicenseParams, paymentToken, ethersjsSf } =
await Fixtures.initializedWithAuction();
const { user } = await getNamedAccounts();
const {
pcoLicenseClaimer,
pcoLicenseParams,
paymentToken,
ethersjsSf,
ethx_erc20,
} = await Fixtures.initializedWithAuction();
const { user, diamondAdmin } = await getNamedAccounts();

const coord = BigNumber.from(4).shl(32).or(BigNumber.from(33));
const contributionRate = ethers.utils
Expand All @@ -340,25 +355,40 @@ describe("PCOLicenseClaimerFacet", async function () {
const requiredBuffer = await ethersjsSf.cfaV1.contract
.connect(await ethers.getSigner(user))
.getDepositRequiredForFlowRate(paymentToken.address, contributionRate);
const approveOp = await paymentToken.approve({
const approveOp = paymentToken.approve({
receiver: pcoLicenseClaimer.address,
amount: forSalePrice.add(requiredBuffer).toString(),
});
await approveOp.exec(await ethers.getSigner(user));

const nextAddress = await pcoLicenseClaimer.getNextProxyAddress(user);

const txn = await pcoLicenseClaimer
.connect(await ethers.getSigner(user))
.claim(contributionRate, forSalePrice, coord, [BigNumber.from(0)]);
await txn.wait();

const requiredBid = await pcoLicenseClaimer.requiredBid();

await expect(txn)
.to.emit(pcoLicenseClaimer, "ParcelClaimed")
.withArgs(0, user);
await expect(txn)
.to.emit(ethx_erc20, "Transfer")
.withArgs(user, nextAddress, requiredBuffer);
await expect(txn)
.to.emit(ethx_erc20, "Transfer")
.withArgs(user, diamondAdmin, requiredBid);
});

it("should claim with real BeaconDiamond", async () => {
const { pcoLicenseClaimer, pcoLicenseParams, ethersjsSf, paymentToken } =
await Fixtures.setup();
const {
pcoLicenseClaimer,
pcoLicenseParams,
ethersjsSf,
paymentToken,
ethx_erc20,
} = await Fixtures.setup();

const { diamondAdmin } = await getNamedAccounts();
const { diamond } = deployments;
Expand Down Expand Up @@ -387,15 +417,15 @@ describe("PCOLicenseClaimerFacet", async function () {
const requiredBuffer = await ethersjsSf.cfaV1.contract
.connect(await ethers.getSigner(user))
.getDepositRequiredForFlowRate(paymentToken.address, contributionRate);
const approveOp = await paymentToken.approve({
const approveOp = paymentToken.approve({
receiver: pcoLicenseClaimer.address,
amount: requiredBuffer.toString(),
});
await approveOp.exec(await ethers.getSigner(user));

// Approve flow creation
const nextAddress = await pcoLicenseClaimer.getNextProxyAddress(user);
const op2 = await ethersjsSf.cfaV1.updateFlowOperatorPermissions({
const op2 = ethersjsSf.cfaV1.updateFlowOperatorPermissions({
superToken: paymentToken.address,
flowOperator: nextAddress,
permissions: 1,
Expand All @@ -412,6 +442,9 @@ describe("PCOLicenseClaimerFacet", async function () {
await expect(txn)
.to.emit(pcoLicenseClaimer, "ParcelClaimed")
.withArgs(0, user);
await expect(txn)
.to.emit(ethx_erc20, "Transfer")
.withArgs(user, nextAddress, requiredBuffer);
});

it("should fail if payment fails", async () => {
Expand All @@ -435,7 +468,7 @@ describe("PCOLicenseClaimerFacet", async function () {
const requiredBuffer = await ethersjsSf.cfaV1.contract
.connect(await ethers.getSigner(user))
.getDepositRequiredForFlowRate(paymentToken.address, contributionRate);
const approveOp = await paymentToken.approve({
const approveOp = paymentToken.approve({
receiver: pcoLicenseClaimer.address,
amount: requiredBuffer.toString(),
});
Expand Down Expand Up @@ -467,10 +500,12 @@ describe("PCOLicenseClaimerFacet", async function () {
const daysFromNow = getUnixTime(addDays(startOfToday(), 7));
await network.provider.send("evm_mine", [daysFromNow]);

const requiredBid = await pcoLicenseClaimer.requiredBid();

// Approve payment token
const approveOp = await paymentToken.approve({
const approveOp = paymentToken.approve({
receiver: pcoLicenseClaimer.address,
amount: forSalePrice.toString(),
amount: requiredBid.toString(),
});
await approveOp.exec(await ethers.getSigner(user));

Expand Down Expand Up @@ -501,7 +536,7 @@ describe("PCOLicenseClaimerFacet", async function () {
const requiredBuffer = await ethersjsSf.cfaV1.contract
.connect(await ethers.getSigner(user))
.getDepositRequiredForFlowRate(paymentToken.address, contributionRate);
const approveOp = await paymentToken.approve({
const approveOp = paymentToken.approve({
receiver: pcoLicenseClaimer.address,
amount: requiredBuffer.toString(),
});
Expand Down

0 comments on commit fe9de0c

Please sign in to comment.