From bbf4b1eea71d47f0c2a387399179d0cd7d63448e Mon Sep 17 00:00:00 2001 From: biscuitdey Date: Wed, 10 Jul 2024 14:34:53 +0530 Subject: [PATCH] Bug fix --- .../bri/ccsm/contracts/CcsmBpiStateAnchor.sol | 2 +- .../ccsm/services/ethereum.service.spec.ts | 41 +++++++++++++++++++ .../src/bri/ccsm/services/ethereum.service.ts | 18 +++++--- 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 examples/bri-3/src/bri/ccsm/services/ethereum.service.spec.ts diff --git a/examples/bri-3/src/bri/ccsm/contracts/CcsmBpiStateAnchor.sol b/examples/bri-3/src/bri/ccsm/contracts/CcsmBpiStateAnchor.sol index 3d2eddbd0..df336a5ca 100644 --- a/examples/bri-3/src/bri/ccsm/contracts/CcsmBpiStateAnchor.sol +++ b/examples/bri-3/src/bri/ccsm/contracts/CcsmBpiStateAnchor.sol @@ -28,7 +28,7 @@ contract CcsmBpiStateAnchor is AccessControl { ); require(bytes(_anchorHash).length > 0, 'AnchorHash cannot be empty'); require( - bytes(_anchorHash).length > 256, + bytes(_anchorHash).length <= 256, 'AnchorHash cannot exceed 256 bytes' ); diff --git a/examples/bri-3/src/bri/ccsm/services/ethereum.service.spec.ts b/examples/bri-3/src/bri/ccsm/services/ethereum.service.spec.ts new file mode 100644 index 000000000..f4cdb7bc2 --- /dev/null +++ b/examples/bri-3/src/bri/ccsm/services/ethereum.service.spec.ts @@ -0,0 +1,41 @@ +import { EthereumService } from './ethereum.service'; + +jest.setTimeout(60000); +describe('Ethereum services', () => { + let ccsm: EthereumService; + + beforeAll(async () => { + ccsm = new EthereumService(); + await ccsm.deployContract(); + }); + + describe('storeAnchorHash', () => { + it('should set anchor hash in the mapping', async () => { + //Arrange + const workgroupdId = '123'; + const anchorHash = 'anchorHash'; + + //Act + await ccsm.storeAnchorHash(workgroupdId, anchorHash); + const ccsmContract = await ccsm.connectToContract({ readonly: true }); + + //Assert + expect(await ccsmContract.AnchorHashStore('workgroupId')).toEqual( + anchorHash, + ); + }); + }); + describe('getAnchorHash', () => { + it('should get anchor hash of the workgroupId from the mapping', async () => { + //Arrange + const workgroupdId = '123'; + const anchorHash = 'anchorHash'; + + //Act + const response = await ccsm.getAnchorHash(workgroupdId); + + //Assert + expect(response).toEqual(anchorHash); + }); + }); +}); diff --git a/examples/bri-3/src/bri/ccsm/services/ethereum.service.ts b/examples/bri-3/src/bri/ccsm/services/ethereum.service.ts index 334d7bcdd..255f71e75 100644 --- a/examples/bri-3/src/bri/ccsm/services/ethereum.service.ts +++ b/examples/bri-3/src/bri/ccsm/services/ethereum.service.ts @@ -6,15 +6,17 @@ import { ethers, Provider, AlchemyProvider, - HDNodeWallet, - Wallet, + BaseWallet, + SigningKey, } from 'ethers'; import * as CcsmBpiStateAnchor from '../../../../zeroKnowledgeArtifacts/blockchain/ethereum/artifacts/artifacts/src/bri/ccsm/contracts/CcsmBpiStateAnchor.sol/CcsmBpiStateAnchor.json'; +import 'dotenv/config'; +import { internalBpiSubjectEcdsaPrivateKey } from '../../../shared/testing/constants'; @Injectable() export class EthereumService implements ICcsmService { private provider: Provider; - private wallet: HDNodeWallet; + private wallet: BaseWallet; constructor() { this.provider = new AlchemyProvider( @@ -22,17 +24,21 @@ export class EthereumService implements ICcsmService { process.env.ALCHEMY_PROVIDER_API_KEY, ); - this.wallet = Wallet.createRandom(this.provider); + const signingKey = new SigningKey('0x' + internalBpiSubjectEcdsaPrivateKey); + + this.wallet = new BaseWallet(signingKey, this.provider); } public async deployContract(): Promise { const ccsmBpiStateAnchorContract = new ethers.ContractFactory( CcsmBpiStateAnchor.abi, CcsmBpiStateAnchor.bytecode, - this.provider, + this.wallet, ); - const deployingContract = await ccsmBpiStateAnchorContract.deploy(); + const deployingContract = await ccsmBpiStateAnchorContract.deploy([ + this.wallet.address, + ]); const deployedContract = await deployingContract.waitForDeployment(); const deployedContractAddress = await deployedContract.getAddress();