Skip to content

Commit

Permalink
fix: added tests, fixed address
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Mar 19, 2024
1 parent 2ac4da2 commit 6e57f13
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
echo "\nRunning GIT hooks..."
yarn cleanbuild
yarn nx affected --target=lint
#yarn nx affected --target=test
yarn nx affected --target=test
12 changes: 6 additions & 6 deletions packages/restapi/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { defineChain } from 'viem';
const { ENV } = Constants;

export const berachainTestnet = defineChain({
const berachainTestnet = defineChain({
id: 80085,
name: 'Berachain Artio',
network: 'berachain-testnet',
Expand Down Expand Up @@ -129,7 +129,7 @@ export const ALIAS_CHAIN_ID = {
[ENV.STAGING]: 80085,
[ENV.DEV]: 80085,
[ENV.LOCAL]: 80085,
}
},
};

export const CHAIN_ID = {
Expand Down Expand Up @@ -160,7 +160,7 @@ export const CHAIN_NAME: { [key: number]: string } = {
122: 'FUSE',
123: 'FUSE',
// berachain
80085: 'BERACHAIN'
80085: 'BERACHAIN',
};
export interface ConfigType {
API_BASE_URL: string;
Expand Down Expand Up @@ -238,7 +238,7 @@ const CONFIG = {
[BLOCKCHAIN_NETWORK.FUSE_MAINNET]: {
API_BASE_URL: API_BASE_URL[ENV.PROD],
EPNS_COMMUNICATOR_CONTRACT: '0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa',
}
},
},
[ENV.STAGING]: {
[BLOCKCHAIN_NETWORK.ETH_SEPOLIA]: {
Expand Down Expand Up @@ -271,7 +271,7 @@ const CONFIG = {
},
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0xA1DF3E68D085aa6918bcc2506b24e499830Db0eB',
EPNS_COMMUNICATOR_CONTRACT: '0x7b9C405e261ba671f008c20D0321f62d08C140EC',
},
},
[ENV.DEV]: {
Expand Down Expand Up @@ -453,7 +453,7 @@ export const VIEM_CONFIG = {
[BLOCKCHAIN_NETWORK.BERACHAIN_TESTNET]: {
NETWORK: berachainTestnet,
API_BASE_URL: API_BASE_URL[ENV.STAGING],
EPNS_COMMUNICATOR_CONTRACT: '0xA1DF3E68D085aa6918bcc2506b24e499830Db0eB',
EPNS_COMMUNICATOR_CONTRACT: '0x7b9C405e261ba671f008c20D0321f62d08C140EC',
},
},
[ENV.DEV]: {
Expand Down
3 changes: 3 additions & 0 deletions packages/restapi/tests/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# ENVIRONMENT | 'STAGING' or 'PROD' or 'DEV'
ENV=env_name

## CHANNEL WITH ALIAS
BERACHAIN_CHANNEL_PRIVATE_KEY=

WALLET_PRIVATE_KEY=your_wallet_private_key
WALLET_PRIVATE_KEY_2=your_wallet_private_key_2
WALLET_RECIPIENT_PK=your_wallet_recipient_pk
Expand Down
86 changes: 86 additions & 0 deletions packages/restapi/tests/lib/alias/berachain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import * as path from 'path';
import * as dotenv from 'dotenv';
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
import * as PUSH_CHANNELS from '../../../src/lib/channels';
import { expect } from 'chai';
import { ethers } from 'ethers';
import { PushAPI, user } from '../../../src';
import { ENV } from '../../../src/lib/constants';

describe('ALIAS functionality', () => {
let userAlice: PushAPI;
let userBob: PushAPI;
let account: string;
let account2: string;
before(async () => {
const provider = new ethers.providers.JsonRpcProvider(
'https://artio.rpc.berachain.com' // berachain artio Provider
);
const signer = new ethers.Wallet(
`0x${process.env['BERACHAIN_CHANNEL_PRIVATE_KEY']}`,
provider
);
account = signer.address;
userAlice = await PushAPI.initialize(signer, {
env: ENV.DEV,
});

const signer2 = new ethers.Wallet(ethers.Wallet.createRandom().privateKey);
account2 = signer2.address;
userBob = await PushAPI.initialize(signer2, { env: ENV.DEV });
});

it.skip('Should be able to create channel', async () => {
const channelInfo = await userAlice.channel.info();
if (channelInfo) return; // skip if already exists
const res = await userAlice.channel.create({
name: 'SDK Alias Test',
description: 'Testing using sdk',
url: 'https://push.org',
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAz0lEQVR4AcXBsU0EQQyG0e+saWJ7oACiKYDMEZVs6GgSpC2BIhzRwAS0sgk9HKn3gpFOAv3v3V4/3+4U4Z1q5KTy42Ql940qvFONnFSGmCFmiN2+fj7uCBlihpgh1ngwcvKfwjuVIWaIGWKNB+GdauSk8uNkJfeNKryzYogZYoZY40m5b/wlQ8wQM8TayMlKeKcaOVkJ71QjJyuGmCFmiDUe+HFy4VyEd57hx0mV+0ZliBlihlgL71w4FyMnVXhnZeSkiu93qheuDDFDzBD7BcCyMAOfy204AAAAAElFTkSuQmCC',
alias: `eip155:80085:${account}`,
progressHook: (progress: any) => console.log(progress),
});
console.log(res);
});

it('Should be able to send notifications', async () => {
await userAlice.channel.send(['*'], {
notification: {
title: 'hi',
body: 'test-broadcast',
},
payload: {
title: 'testing broadcast notification',
body: 'testing with random body',
cta: 'https://google.com/',
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4',
},
channel: `eip155:80085:${account}`,
});
});

it('Should be able to add delegatee', async () => {
await userAlice.channel.delegate.add(account2);
});

it('Should be able to send notifications from delegate', async () => {
await userBob.channel.send(['*'], {
notification: {
title: 'hi',
body: 'test-broadcast',
},
payload: {
title: 'testing broadcast notification',
body: 'testing with random body',
cta: 'https://google.com/',
embed: 'https://avatars.githubusercontent.com/u/64157541?s=200&v=4',
},
channel: `eip155:80085:${account}`,
});
});

it('Should be able to remove delegatee', async () => {
await userAlice.channel.delegate.remove(account2);
});
});

0 comments on commit 6e57f13

Please sign in to comment.