Skip to content

Commit

Permalink
Merge pull request #477 from magiclabs/sc-68969-immutable-stark-error
Browse files Browse the repository at this point in the history
Sc 68969 immutable stark error
  • Loading branch information
mattupham authored Mar 20, 2023
2 parents 8e8387e + 15e4f10 commit 4c47993
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 44 deletions.
2 changes: 2 additions & 0 deletions packages/@magic-sdk/provider/src/core/sdk-exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class MagicRPCError extends Error {

public code: RPCErrorCode | number;
public rawMessage: string;
public data: any;

constructor(sourceError?: JsonRpcError | null) {
super();
Expand All @@ -36,6 +37,7 @@ export class MagicRPCError extends Error {
this.rawMessage = sourceError?.message || 'Internal error';
this.code = isJsonRpcErrorCode(codeNormalized) ? codeNormalized : RPCErrorCode.InternalError;
this.message = `Magic RPC Error: [${this.code}] ${this.rawMessage}`;
this.data = sourceError?.data || undefined;

Object.setPrototypeOf(this, MagicRPCError.prototype);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import browserEnv from '@ikscodes/browser-env';
import { MagicRPCError } from '../../../../../src/core/sdk-exceptions';

const exampleData =
'0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000011555345525f554e52454749535445524544000000000000000000000000000000';

beforeEach(() => {
browserEnv.restore();
});
Expand All @@ -9,12 +12,14 @@ test('Initialize `MagicRPCError` with object argument', () => {
const err = new MagicRPCError({
code: -32603,
message: 'hello world',
data: exampleData,
});

expect(err instanceof MagicRPCError).toBe(true);
expect(err.code).toBe(-32603);
expect(err.message).toBe('Magic RPC Error: [-32603] hello world');
expect(err.rawMessage).toBe('hello world');
expect(err.data).toBe(exampleData);
});

test('Initialize MagicRPCError with `null` argument', () => {
Expand All @@ -24,6 +29,7 @@ test('Initialize MagicRPCError with `null` argument', () => {
expect(err.code).toBe(-32603);
expect(err.message).toBe('Magic RPC Error: [-32603] Internal error');
expect(err.rawMessage).toBe('Internal error');
expect(err.data).toBe(undefined);
});

test('Initialize MagicRPCError with `undefined` argument', () => {
Expand All @@ -33,16 +39,20 @@ test('Initialize MagicRPCError with `undefined` argument', () => {
expect(err.code).toBe(-32603);
expect(err.message).toBe('Magic RPC Error: [-32603] Internal error');
expect(err.rawMessage).toBe('Internal error');
expect(err.data).toBe(undefined);
});

test('Initialize MagicRPCError with unknown error code argument', () => {
const err = new MagicRPCError({
// @ts-ignore
code: 1,
message: 'hello world',
data: exampleData,
});

expect(err instanceof MagicRPCError).toBe(true);
expect(err.code).toBe(-32603);
expect(err.message).toBe('Magic RPC Error: [-32603] hello world');
expect(err.rawMessage).toBe('hello world');
expect(err.data).toBe(exampleData);
});
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ test('Resolves with a successful response', async () => {
test('Rejects with a `MagicRPCError` upon request failed', async () => {
const response = new JsonRpcResponse(requestPayload).applyError({ code: -32603, message: 'hello world' });
const { baseModule } = createBaseModule(jest.fn().mockImplementation(() => Promise.resolve(response)));
const expectedError = new MagicRPCError({ code: -32603, message: 'hello world' });
const expectedError = new MagicRPCError({
code: -32603,
message: 'hello world',
data: '0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000011555345525f554e52454749535445524544000000000000000000000000000000',
});
await expect(() => baseModule.request(requestPayload)).rejects.toThrow(expectedError);
});

Expand Down
1 change: 1 addition & 0 deletions packages/@magic-sdk/types/src/core/json-rpc-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface JsonRpcBatchRequestCallback {
export interface JsonRpcError {
message: string;
code: RPCErrorCode;
data?: any;
}

export interface JsonRpcResponsePayload<ResultType = any> {
Expand Down
86 changes: 43 additions & 43 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2731,63 +2731,63 @@ __metadata:
version: 0.0.0-use.local
resolution: "@magic-ext/algorand@workspace:packages/@magic-ext/algorand"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/avalanche@workspace:packages/@magic-ext/avalanche":
version: 0.0.0-use.local
resolution: "@magic-ext/avalanche@workspace:packages/@magic-ext/avalanche"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/bitcoin@workspace:packages/@magic-ext/bitcoin":
version: 0.0.0-use.local
resolution: "@magic-ext/bitcoin@workspace:packages/@magic-ext/bitcoin"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/conflux@workspace:packages/@magic-ext/conflux":
version: 0.0.0-use.local
resolution: "@magic-ext/conflux@workspace:packages/@magic-ext/conflux"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/connect@workspace:packages/@magic-ext/connect":
version: 0.0.0-use.local
resolution: "@magic-ext/connect@workspace:packages/@magic-ext/connect"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/cosmos@workspace:packages/@magic-ext/cosmos":
version: 0.0.0-use.local
resolution: "@magic-ext/cosmos@workspace:packages/@magic-ext/cosmos"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/ed25519@workspace:packages/@magic-ext/ed25519":
version: 0.0.0-use.local
resolution: "@magic-ext/ed25519@workspace:packages/@magic-ext/ed25519"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/flow@workspace:packages/@magic-ext/flow":
version: 0.0.0-use.local
resolution: "@magic-ext/flow@workspace:packages/@magic-ext/flow"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
"@onflow/fcl": 0.0.41
"@onflow/types": 0.0.3
peerDependencies:
Expand All @@ -2800,34 +2800,34 @@ __metadata:
version: 0.0.0-use.local
resolution: "@magic-ext/harmony@workspace:packages/@magic-ext/harmony"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/icon@workspace:packages/@magic-ext/icon":
version: 0.0.0-use.local
resolution: "@magic-ext/icon@workspace:packages/@magic-ext/icon"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/near@workspace:packages/@magic-ext/near":
version: 0.0.0-use.local
resolution: "@magic-ext/near@workspace:packages/@magic-ext/near"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/oauth@^7.5.0, @magic-ext/oauth@workspace:packages/@magic-ext/oauth":
"@magic-ext/oauth@^7.6.0, @magic-ext/oauth@workspace:packages/@magic-ext/oauth":
version: 0.0.0-use.local
resolution: "@magic-ext/oauth@workspace:packages/@magic-ext/oauth"
dependencies:
"@magic-sdk/types": ^11.5.0
"@magic-sdk/types": ^11.6.0
"@types/crypto-js": ~3.1.47
crypto-js: ^3.3.0
magic-sdk: ^13.5.0
magic-sdk: ^13.6.0
languageName: unknown
linkType: soft

Expand All @@ -2843,15 +2843,15 @@ __metadata:
version: 0.0.0-use.local
resolution: "@magic-ext/polkadot@workspace:packages/@magic-ext/polkadot"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/react-native-bare-oauth@workspace:packages/@magic-ext/react-native-bare-oauth":
version: 0.0.0-use.local
resolution: "@magic-ext/react-native-bare-oauth@workspace:packages/@magic-ext/react-native-bare-oauth"
dependencies:
"@magic-sdk/react-native-bare": ^14.5.0
"@magic-sdk/react-native-bare": ^14.6.0
"@magic-sdk/types": ^10.0.1
"@types/crypto-js": ~3.1.47
crypto-js: ^3.3.0
Expand All @@ -2867,7 +2867,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@magic-ext/react-native-expo-oauth@workspace:packages/@magic-ext/react-native-expo-oauth"
dependencies:
"@magic-sdk/react-native-expo": ^14.5.0
"@magic-sdk/react-native-expo": ^14.6.0
"@magic-sdk/types": ^10.0.0
"@types/crypto-js": ~3.1.47
crypto-js: ^3.3.0
Expand All @@ -2882,56 +2882,56 @@ __metadata:
version: 0.0.0-use.local
resolution: "@magic-ext/solana@workspace:packages/@magic-ext/solana"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/taquito@workspace:packages/@magic-ext/taquito":
version: 0.0.0-use.local
resolution: "@magic-ext/taquito@workspace:packages/@magic-ext/taquito"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/terra@workspace:packages/@magic-ext/terra":
version: 0.0.0-use.local
resolution: "@magic-ext/terra@workspace:packages/@magic-ext/terra"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/tezos@workspace:packages/@magic-ext/tezos":
version: 0.0.0-use.local
resolution: "@magic-ext/tezos@workspace:packages/@magic-ext/tezos"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/webauthn@workspace:packages/@magic-ext/webauthn":
version: 0.0.0-use.local
resolution: "@magic-ext/webauthn@workspace:packages/@magic-ext/webauthn"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-ext/zilliqa@workspace:packages/@magic-ext/zilliqa":
version: 0.0.0-use.local
resolution: "@magic-ext/zilliqa@workspace:packages/@magic-ext/zilliqa"
dependencies:
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/commons": ^9.6.0
languageName: unknown
linkType: soft

"@magic-sdk/commons@^9.5.0, @magic-sdk/commons@workspace:packages/@magic-sdk/commons":
"@magic-sdk/commons@^9.6.0, @magic-sdk/commons@workspace:packages/@magic-sdk/commons":
version: 0.0.0-use.local
resolution: "@magic-sdk/commons@workspace:packages/@magic-sdk/commons"
dependencies:
"@magic-sdk/provider": ^13.5.0
"@magic-sdk/types": ^11.5.0
"@magic-sdk/provider": ^13.6.0
"@magic-sdk/types": ^11.6.0
peerDependencies:
"@magic-sdk/provider": ">=4.3.0"
"@magic-sdk/types": ">=3.1.1"
Expand All @@ -2955,17 +2955,17 @@ __metadata:
"@babel/core": ^7.9.6
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-ext/oauth": ^7.5.0
magic-sdk: ^13.5.0
"@magic-ext/oauth": ^7.6.0
magic-sdk: ^13.6.0
languageName: unknown
linkType: soft

"@magic-sdk/provider@^13.5.0, @magic-sdk/provider@workspace:packages/@magic-sdk/provider":
"@magic-sdk/provider@^13.6.0, @magic-sdk/provider@workspace:packages/@magic-sdk/provider":
version: 0.0.0-use.local
resolution: "@magic-sdk/provider@workspace:packages/@magic-sdk/provider"
dependencies:
"@babel/plugin-transform-modules-commonjs": ^7.9.6
"@magic-sdk/types": ^11.5.0
"@magic-sdk/types": ^11.6.0
"@peculiar/webcrypto": ^1.1.7
eventemitter3: ^4.0.4
localforage: ^1.7.4
Expand All @@ -2990,17 +2990,17 @@ __metadata:
languageName: node
linkType: hard

"@magic-sdk/react-native-bare@^14.5.0, @magic-sdk/react-native-bare@workspace:packages/@magic-sdk/react-native-bare":
"@magic-sdk/react-native-bare@^14.6.0, @magic-sdk/react-native-bare@workspace:packages/@magic-sdk/react-native-bare":
version: 0.0.0-use.local
resolution: "@magic-sdk/react-native-bare@workspace:packages/@magic-sdk/react-native-bare"
dependencies:
"@aveq-research/localforage-asyncstorage-driver": ^3.0.1
"@babel/core": ^7.15.0
"@babel/plugin-transform-flow-strip-types": ^7.14.5
"@babel/runtime": ~7.10.4
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/provider": ^13.5.0
"@magic-sdk/types": ^11.5.0
"@magic-sdk/commons": ^9.6.0
"@magic-sdk/provider": ^13.6.0
"@magic-sdk/types": ^11.6.0
"@react-native-async-storage/async-storage": ^1.15.5
"@react-native-community/async-storage": ^1.12.1
"@types/lodash": ^4.14.158
Expand All @@ -3027,17 +3027,17 @@ __metadata:
languageName: unknown
linkType: soft

"@magic-sdk/react-native-expo@^14.5.0, @magic-sdk/react-native-expo@workspace:packages/@magic-sdk/react-native-expo":
"@magic-sdk/react-native-expo@^14.6.0, @magic-sdk/react-native-expo@workspace:packages/@magic-sdk/react-native-expo":
version: 0.0.0-use.local
resolution: "@magic-sdk/react-native-expo@workspace:packages/@magic-sdk/react-native-expo"
dependencies:
"@aveq-research/localforage-asyncstorage-driver": ^3.0.1
"@babel/core": ^7.15.0
"@babel/plugin-transform-flow-strip-types": ^7.14.5
"@babel/runtime": ~7.10.4
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/provider": ^13.5.0
"@magic-sdk/types": ^11.5.0
"@magic-sdk/commons": ^9.6.0
"@magic-sdk/provider": ^13.6.0
"@magic-sdk/types": ^11.6.0
"@react-native-async-storage/async-storage": ^1.15.5
"@types/lodash": ^4.14.158
buffer: ~5.6.0
Expand All @@ -3063,7 +3063,7 @@ __metadata:
languageName: unknown
linkType: soft

"@magic-sdk/types@^11.5.0, @magic-sdk/types@workspace:packages/@magic-sdk/types":
"@magic-sdk/types@^11.6.0, @magic-sdk/types@workspace:packages/@magic-sdk/types":
version: 0.0.0-use.local
resolution: "@magic-sdk/types@workspace:packages/@magic-sdk/types"
languageName: unknown
Expand Down Expand Up @@ -12338,16 +12338,16 @@ fsevents@^2.3.2:
languageName: unknown
linkType: soft

"magic-sdk@^13.5.0, magic-sdk@workspace:packages/magic-sdk":
"magic-sdk@^13.6.0, magic-sdk@workspace:packages/magic-sdk":
version: 0.0.0-use.local
resolution: "magic-sdk@workspace:packages/magic-sdk"
dependencies:
"@babel/core": ^7.9.6
"@babel/plugin-proposal-optional-chaining": ^7.9.0
"@babel/runtime": ^7.9.6
"@magic-sdk/commons": ^9.5.0
"@magic-sdk/provider": ^13.5.0
"@magic-sdk/types": ^11.5.0
"@magic-sdk/commons": ^9.6.0
"@magic-sdk/provider": ^13.6.0
"@magic-sdk/types": ^11.6.0
localforage: ^1.7.4
localforage-driver-memory: ^1.0.5
languageName: unknown
Expand Down

0 comments on commit 4c47993

Please sign in to comment.