-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(rwa): interpret error messages (#2838)
- Loading branch information
1 parent
caa1b09
commit 0deacb4
Showing
3 changed files
with
206 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
packages/apps/rwa-demo/src/utils/__tests__/interpretMessage.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import type { ITransaction } from '@/components/TransactionsProvider/TransactionsProvider'; | ||
import { interpretMessage } from '../interpretMessage'; | ||
|
||
describe('interpretMessage', () => { | ||
it('should return the default error when no interpert text is found is found', () => { | ||
const data = { | ||
type: 'Skeletor', | ||
} as unknown as ITransaction; | ||
expect(interpretMessage('There is no error', data)).toEqual( | ||
'Skeletor: There is no error', | ||
); | ||
|
||
expect(interpretMessage('There is no error')).toEqual('There is no error'); | ||
}); | ||
|
||
it('should return correct text when row is not found', () => { | ||
const data = { | ||
type: 'he-man', | ||
} as unknown as ITransaction; | ||
expect( | ||
interpretMessage('This error Insert: row found for key', data), | ||
).toEqual('he-man: This key already exists'); | ||
}); | ||
|
||
it('should return correct text when buying of gas failed', () => { | ||
expect(interpretMessage('This error buy gas failed')).toEqual( | ||
'This account does not have enough balance to pay for Gas', | ||
); | ||
}); | ||
it('should return correct text when exceeds max investors', () => { | ||
expect(interpretMessage('This error exceeds max investor')).toEqual( | ||
'The maximum amount of investors has been reached', | ||
); | ||
}); | ||
it('should return correct text when there is a duplicate in the table', () => { | ||
expect( | ||
interpretMessage('This error exceeds PactDuplicateTableError'), | ||
).toEqual('This already exists'); | ||
}); | ||
it('should return the correct text when an erorcode is found in the string', () => { | ||
expect(interpretMessage('This error PAU-001')).toEqual( | ||
'Contract is already paused.', | ||
); | ||
expect(interpretMessage('This error PAU-002')).toEqual( | ||
'Contract is already unpaused.', | ||
); | ||
expect(interpretMessage('This error IDR-001')).toEqual( | ||
'User is not registered.', | ||
); | ||
expect(interpretMessage('This error IDR-002')).toEqual( | ||
'User must have a zero balance before identity removal.', | ||
); | ||
expect(interpretMessage('This error ACC-PRT-001')).toEqual( | ||
'Single-key account protocol violation.', | ||
); | ||
expect(interpretMessage('This error ACC-PRT-002')).toEqual( | ||
'Reserved protocol guard violation.', | ||
); | ||
expect(interpretMessage('This error ACC-PRT-003')).toEqual( | ||
'Invalid sender or receiver.', | ||
); | ||
expect(interpretMessage('This error ACC-FRZ-001')).toEqual( | ||
'Account is frozen. Partial freeze is not available.', | ||
); | ||
expect(interpretMessage('This error ACC-AMT-001')).toEqual( | ||
'Account has insufficient funds.', | ||
); | ||
expect(interpretMessage('This error TRF-ACC-001')).toEqual( | ||
'Same sender and receiver.', | ||
); | ||
expect(interpretMessage('This error TRF-PAUSE-001')).toEqual( | ||
'Transfer is not permitted because contract is paused.', | ||
); | ||
expect(interpretMessage('This error TRF-AMT-002')).toEqual( | ||
'Transfer amount must be positive.', | ||
); | ||
expect(interpretMessage('This error TRF-MGR-001')).toEqual( | ||
'Managed Transfer Capability balance has exceeded.', | ||
); | ||
expect(interpretMessage('This error TRF-CAP-001')).toEqual( | ||
'Transfer capability was not achieved.', | ||
); | ||
expect(interpretMessage('This error FRZ-AMT-002')).toEqual( | ||
'Frozen amount exceeds available balance.', | ||
); | ||
expect(interpretMessage('This error FRZ-AMT-003')).toEqual( | ||
'Amount to freeze must be positive.', | ||
); | ||
expect(interpretMessage('This error FRZ-AMT-004')).toEqual( | ||
'Amount to unfreeze must be positive.', | ||
); | ||
expect(interpretMessage('This error ROL-001')).toEqual( | ||
'Caller must be either the owner or an agent-admin.', | ||
); | ||
expect(interpretMessage('This error ROL-002')).toEqual( | ||
'Role does not exist in predefined agent roles.', | ||
); | ||
expect(interpretMessage('This error ROL-STS-001')).toEqual( | ||
'Agent cannot be added if the agent is already active.', | ||
); | ||
expect(interpretMessage('This error ROL-STS-002')).toEqual( | ||
'Agent is not removed.', | ||
); | ||
expect(interpretMessage('This error ROL-STS-003')).toEqual( | ||
'Agent does not contain the role.', | ||
); | ||
expect(interpretMessage('This error GEN-IMPL-001')).toEqual( | ||
'Function exists to implement interface, but is not being used.', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import type { ITransaction } from '@/components/TransactionsProvider/TransactionsProvider'; | ||
|
||
export const interpretMessage = (str: string, data?: ITransaction): string => { | ||
//error codes in the RWA contract which can be returned by the RWA contract | ||
if (str?.includes('PAU-001')) { | ||
return `Contract is already paused.`; | ||
} | ||
if (str?.includes('PAU-002')) { | ||
return `Contract is already unpaused.`; | ||
} | ||
if (str?.includes('IDR-001')) { | ||
return `User is not registered.`; | ||
} | ||
if (str?.includes('IDR-002')) { | ||
return `User must have a zero balance before identity removal.`; | ||
} | ||
if (str?.includes('ACC-PRT-001')) { | ||
return `Single-key account protocol violation.`; | ||
} | ||
if (str?.includes('ACC-PRT-002')) { | ||
return `Reserved protocol guard violation.`; | ||
} | ||
if (str?.includes('ACC-PRT-003')) { | ||
return `Invalid sender or receiver.`; | ||
} | ||
if (str?.includes('ACC-FRZ-001')) { | ||
return `Account is frozen. Partial freeze is not available.`; | ||
} | ||
if (str?.includes('ACC-AMT-001')) { | ||
return `Account has insufficient funds.`; | ||
} | ||
if (str?.includes('TRF-ACC-001')) { | ||
return `Same sender and receiver.`; | ||
} | ||
if (str?.includes('TRF-PAUSE-001')) { | ||
return `Transfer is not permitted because contract is paused.`; | ||
} | ||
if (str?.includes('TRF-AMT-002')) { | ||
return `Transfer amount must be positive.`; | ||
} | ||
if (str?.includes('TRF-MGR-001')) { | ||
return `Managed Transfer Capability balance has exceeded.`; | ||
} | ||
if (str?.includes('TRF-CAP-001')) { | ||
return `Transfer capability was not achieved.`; | ||
} | ||
if (str?.includes('FRZ-AMT-002')) { | ||
return `Frozen amount exceeds available balance.`; | ||
} | ||
if (str?.includes('FRZ-AMT-003')) { | ||
return `Amount to freeze must be positive.`; | ||
} | ||
if (str?.includes('FRZ-AMT-004')) { | ||
return `Amount to unfreeze must be positive.`; | ||
} | ||
if (str?.includes('ROL-001')) { | ||
return `Caller must be either the owner or an agent-admin.`; | ||
} | ||
if (str?.includes('ROL-002')) { | ||
return `Role does not exist in predefined agent roles.`; | ||
} | ||
if (str?.includes('ROL-STS-001')) { | ||
return `Agent cannot be added if the agent is already active.`; | ||
} | ||
if (str?.includes('ROL-STS-002')) { | ||
return `Agent is not removed.`; | ||
} | ||
if (str?.includes('ROL-STS-003')) { | ||
return `Agent does not contain the role.`; | ||
} | ||
if (str?.includes('GEN-IMPL-001')) { | ||
return `Function exists to implement interface, but is not being used.`; | ||
} | ||
|
||
// misc | ||
if (str?.includes('Insert: row found for key')) { | ||
return `${data?.type}: This key already exists`; | ||
} | ||
if (str?.includes('buy gas failed')) { | ||
return `This account does not have enough balance to pay for Gas`; | ||
} | ||
if (str?.includes('exceeds max investor')) { | ||
return `The maximum amount of investors has been reached`; | ||
} | ||
if (str?.includes('PactDuplicateTableError')) { | ||
return `This already exists`; | ||
} | ||
|
||
if (data?.type) { | ||
return `${data?.type}: ${str}`; | ||
} | ||
|
||
return `${str}`; | ||
}; |