diff --git a/.husky/pre-commit b/.husky/pre-commit index 8a79c3470..2665d0376 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -4,4 +4,4 @@ echo "\nRunning GIT hooks..." yarn cleanbuild yarn nx affected --target=lint -#yarn nx affected --target=test \ No newline at end of file +yarn nx affected --target=test \ No newline at end of file diff --git a/packages/restapi/src/lib/config.ts b/packages/restapi/src/lib/config.ts index 8265afc8d..e8b89f2e2 100644 --- a/packages/restapi/src/lib/config.ts +++ b/packages/restapi/src/lib/config.ts @@ -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', @@ -129,7 +129,7 @@ export const ALIAS_CHAIN_ID = { [ENV.STAGING]: 80085, [ENV.DEV]: 80085, [ENV.LOCAL]: 80085, - } + }, }; export const CHAIN_ID = { @@ -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; @@ -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]: { @@ -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]: { @@ -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]: { diff --git a/packages/restapi/tests/.env.sample b/packages/restapi/tests/.env.sample index 7f97b7f13..440b64226 100644 --- a/packages/restapi/tests/.env.sample +++ b/packages/restapi/tests/.env.sample @@ -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 diff --git a/packages/restapi/tests/lib/alias/berachain.test.ts b/packages/restapi/tests/lib/alias/berachain.test.ts new file mode 100644 index 000000000..9fb816d67 --- /dev/null +++ b/packages/restapi/tests/lib/alias/berachain.test.ts @@ -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); + }); +});