From 7621b309fd69450cd77b215c64a2be53243d7323 Mon Sep 17 00:00:00 2001 From: louyuqi Date: Tue, 15 Oct 2024 16:50:36 +0800 Subject: [PATCH] feat:Add BOP platform support and corresponding tests 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. --- contracts/mocks/MockHttpGetBool.sol | 14 +++++++++++++ contracts/platform_user/BOPClient.sol | 16 +++++++++++++++ contracts/platform_user/PlatformUser.sol | 10 +++++++++- tests/platform-user.ts | 25 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 contracts/platform_user/BOPClient.sol diff --git a/contracts/mocks/MockHttpGetBool.sol b/contracts/mocks/MockHttpGetBool.sol index 3d05113..4e01298 100644 --- a/contracts/mocks/MockHttpGetBool.sol +++ b/contracts/mocks/MockHttpGetBool.sol @@ -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); diff --git a/contracts/platform_user/BOPClient.sol b/contracts/platform_user/BOPClient.sol new file mode 100644 index 0000000..3455331 --- /dev/null +++ b/contracts/platform_user/BOPClient.sol @@ -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); + } +} diff --git a/contracts/platform_user/PlatformUser.sol b/contracts/platform_user/PlatformUser.sol index 8725f30..a15aea3 100644 --- a/contracts/platform_user/PlatformUser.sol +++ b/contracts/platform_user/PlatformUser.sol @@ -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 { @@ -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; + } } } @@ -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; } diff --git a/tests/platform-user.ts b/tests/platform-user.ts index 57b9b09..f6d17c1 100644 --- a/tests/platform-user.ts +++ b/tests/platform-user.ts @@ -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) + }) + }) })