Skip to content

Commit

Permalink
feat:Add BOP platform support and corresponding tests
Browse files Browse the repository at this point in the history
Introduced support for the BOP platform by adding `BOPClient` library and updating `PlatformUser` contract. Mocked the HTTP request for BOP and added tests to validate BOP user recognition.
  • Loading branch information
louisian committed Oct 15, 2024
1 parent bbf9c45 commit 7621b30
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
14 changes: 14 additions & 0 deletions contracts/mocks/MockHttpGetBool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ contract MockHttpGetBool {
)
) {
success = false;
} else if (
Strings.equal(
url,
"https://bop.burve.workers.dev/?address=0x96aEb2216810C624131c51141da612808103d319"
)
) {
value = true;
} else if (
Strings.equal(
url,
"https://bop.burve.workers.dev/?address=0xA9d439F4DED81152DB00CB7CD94A8d908FEF903e"
)
) {
value = false;
}

console.log("http_get_bool>>", url, jsonPointer, value);
Expand Down
16 changes: 16 additions & 0 deletions contracts/platform_user/BOPClient.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.8;
import "../libraries/Http.sol";
import "../libraries/Utils.sol";
import "../libraries/Identities.sol";

library BOPClient {
function talentAsset(string memory account) internal returns (bool, bool) {
string memory url = "https://bop.burve.workers.dev/?address=";

url = string(abi.encodePacked(url, account));

HttpHeader[] memory headers = new HttpHeader[](0);
return Http.GetBool(url, "/data", headers);
}
}
10 changes: 9 additions & 1 deletion contracts/platform_user/PlatformUser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import "../libraries/Identities.sol";
import "../libraries/Utils.sol";
import "../DynamicAssertion.sol";
import "./DarenMarketClient.sol";
import "./BOPClient.sol";

library PlatformType {
string public constant KaratDao = "KaratDao";
string public constant MagicCraft = "MagicCraft";
string public constant DarenMarket = "DarenMarket";
string public constant BOP = "BOP";
}

contract PlatformUser is DynamicAssertion {
Expand Down Expand Up @@ -116,6 +118,11 @@ contract PlatformUser is DynamicAssertion {
if (success) {
isPlatformUser = result;
}
} else if (Strings.equal(platformName, PlatformType.BOP)) {
(bool success, bool result) = BOPClient.talentAsset(identityString);
if (success) {
isPlatformUser = result;
}
}
}

Expand All @@ -125,7 +132,8 @@ contract PlatformUser is DynamicAssertion {
if (
Strings.equal(platformName, PlatformType.KaratDao) ||
Strings.equal(platformName, PlatformType.MagicCraft) ||
Strings.equal(platformName, PlatformType.DarenMarket)
Strings.equal(platformName, PlatformType.DarenMarket) ||
Strings.equal(platformName, PlatformType.BOP)
) {
supported = true;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/platform-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,29 @@ describe('PlatformUser', () => {
await expectDarenMarketResult(PlatformUser, val, true)
})
})
describe('BOP', () => {
const BOPParams = generateParams('BOP')

const expectBOPResult = (contract: any, val: any, result: boolean) =>
expectResult(contract, val, 'BOP', result)
it('should return result true if is platform user', async () => {
const { PlatformUser } = await loadFixture(deployFixture)
const val = PlatformUser.execute(
// identities
[
{
identity_type: IdentityType.Evm,
value: ethers.toUtf8Bytes(
'0x96aEb2216810C624131c51141da612808103d319'
),
networks: [Web3Network.Ethereum, Web3Network.Bsc],
},
],
[],
// params
BOPParams
)
await expectBOPResult(PlatformUser, val, true)
})
})
})

0 comments on commit 7621b30

Please sign in to comment.