Skip to content

Commit

Permalink
test(eos): test set chain id function
Browse files Browse the repository at this point in the history
  • Loading branch information
envin3 committed Nov 10, 2024
1 parent fbde486 commit b36e8df
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cpp/test/adapter-local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe('Adapter Testing - Local deployment', () => {
'000000000000000000000000bcf063a9eb18bc3c6eb005791c61801b7cb16fe4'
const evmTopicZero =
'66756e6473206172652073616675207361667520736166752073616675202e2e'
const EOSChainId =
'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'

const token = {
symbol: symbol,
Expand Down Expand Up @@ -198,6 +200,12 @@ describe('Adapter Testing - Local deployment', () => {
.send(active(adapter.account))
})

it('Should set the local chain id successfully', async () => {
await adapter.contract.actions
.setchainid([EOSChainId])
.send(active(adapter.account))
})

it('Should add the tee public key successfully', async () => {
const teePubKey = fromEthersPublicKey(
evmEA.signingKey.compressedPublicKey,
Expand Down
8 changes: 8 additions & 0 deletions cpp/test/adapter-non-local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('Adapter Testing - Non Local Deployment', () => {
'000000000000000000000000bcf063a9eb18bc3c6eb005791c61801b7cb16fe4'
const evmTopicZero =
'66756e6473206172652073616675207361667520736166752073616675202e2e'
const EOSChainId =
'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'

const token = {
symbol,
Expand Down Expand Up @@ -181,6 +183,12 @@ describe('Adapter Testing - Non Local Deployment', () => {
.send(active(adapter.account))
})

it('Should set the local chain id successfully', async () => {
await adapter.contract.actions
.setchainid([EOSChainId])
.send(active(adapter.account))
})

it('Should add the tee public key successfully', async () => {
const teePubKey = fromEthersPublicKey(
evmEA.signingKey.compressedPublicKey,
Expand Down
35 changes: 35 additions & 0 deletions cpp/test/adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const { TimePointSec } = require('@wharfkit/antelope')
const TEE_ADDRESS_CHANGE_GRACE_PERIOD_MS = 172800 * 1000
const TABLE_STORAGE = 'storage'
const TABLE_TEE = 'tee'
const TABLE_LOCAL_CHAIN_ID = 'chainid'

describe('Adapter tests', () => {
const symbol = 'TST'
Expand All @@ -48,6 +49,8 @@ describe('Adapter tests', () => {
'000000000000000000000000bcf063a9eb18bc3c6eb005791c61801b7cb16fe4'
const evmTopicZero =
'66756e6473206172652073616675207361667520736166752073616675202e2e'
const EOSChainId =
'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'

const token = {
symbol,
Expand Down Expand Up @@ -367,6 +370,38 @@ describe('Adapter tests', () => {
})
})

describe('adapter::setchainid', () => {
it('Should throw if called by not authorized account', async () => {
const action = adapter.contract.actions
.setchainid([EOSChainId])
.send(active(evil))

await expectToThrow(action, errors.AUTH_MISSING(adapter.account))
})

it('Should set the local chain id correctly', async () => {
const chain_id = 'ababba'
await adapter.contract.actions
.setchainid([chain_id])
.send(active(adapter.account))

const local_chain_id = getSingletonInstance(
adapter.contract,
TABLE_LOCAL_CHAIN_ID,
)
expect(local_chain_id.chain_id).to.be.equal(chain_id)
})

it('Should update the local chain id correctly', async () => {
await adapter.contract.actions
.setchainid([EOSChainId])
.send(active(adapter.account))

const local_chain_id = getSingletonInstance(adapter.contract, 'chainid')
expect(local_chain_id.chain_id).to.be.equal(EOSChainId)
})
})

describe('adapter::settee', () => {
it('Should throw if called by not authorized account', async () => {
const action = adapter.contract.actions
Expand Down
16 changes: 15 additions & 1 deletion cpp/test/pam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe('PAM testing', () => {
const evmEmitter = '0x5623D0aF4bfb6F7B18d6618C166d518E4357ceE2'
const evmTopic0 =
'0x66756e6473206172652073616675207361667520736166752073616675202e2e'
const EOSChainId =
'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'

const recipient = 'recipient'

Expand Down Expand Up @@ -104,12 +106,24 @@ describe('PAM testing', () => {
)
})

it('Should reject when the local chain id is not set', async () => {
const action = pam.contract.actions
.isauthorized([operation, metadata])
.send(active(user))

await expectToThrow(action, errors.LOCAL_CHAIN_NOT_SET)
})

it('Should reject when the public key is not set', async () => {
await adapter.contract.actions
.setchainid([EOSChainId])
.send(active(adapter.account))

const action = pam.contract.actions
.isauthorized([operation, metadata])
.send(active(user))

await expectToThrow(action, errors.SINGLETON_NOT_EXISTING)
await expectToThrow(action, errors.TEE_NOT_SET)
})

it('Should reject when the origin_chain_id is not set', async () => {
Expand Down
7 changes: 5 additions & 2 deletions cpp/test/utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const INVALID_MINFEE_SYMBOL = eosio_assert('invalid minimum fee symbol')

const NOT_INITIALIZED = eosio_assert('adapter contract not initialized')

const SINGLETON_NOT_EXISTING = eosio_assert('singleton does not exist')
const TEE_NOT_SET = eosio_assert('tee singleton not set')

const LOCAL_CHAIN_NOT_SET = eosio_assert('local chain id singleton not set')

const ORIGIN_CHAINID_NOT_REGISTERED = eosio_assert(
'origin chain_id not registered',
Expand Down Expand Up @@ -93,7 +95,8 @@ module.exports = {
INVALID_MINFEE_SYMBOL,
NOT_INITIALIZED,
SYMBOL_NOT_FOUND,
SINGLETON_NOT_EXISTING,
TEE_NOT_SET,
LOCAL_CHAIN_NOT_SET,
ORIGIN_CHAINID_NOT_REGISTERED,
INVALID_SIGNATURE,
UNEXPECTED_EMITTER,
Expand Down

0 comments on commit b36e8df

Please sign in to comment.