Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
biscuitdey committed Jul 10, 2024
1 parent 0464d30 commit bbf4b1e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
41 changes: 41 additions & 0 deletions examples/bri-3/src/bri/ccsm/services/ethereum.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
18 changes: 12 additions & 6 deletions examples/bri-3/src/bri/ccsm/services/ethereum.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,39 @@ 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(
process.env.ALCHEMY_PROVIDER_NETWORK,
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<void> {
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();
Expand Down

0 comments on commit bbf4b1e

Please sign in to comment.