-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a82d43
commit 262b511
Showing
7 changed files
with
246 additions
and
105 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
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
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
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
91 changes: 91 additions & 0 deletions
91
packages/policy-engine-shared/src/lib/__test__/unit/action.type.spec.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,91 @@ | ||
import { toHex } from 'viem' | ||
import { Action, SignTypedDataAction } from '../../type/action.type' | ||
|
||
describe('SignTypedDataAction', () => { | ||
const typedData = { | ||
domain: { | ||
name: 'Ether Mail', | ||
version: '1', | ||
chainId: 1, | ||
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' | ||
}, | ||
types: { | ||
Person: [ | ||
{ name: 'name', type: 'string' }, | ||
{ name: 'wallet', type: 'address' } | ||
], | ||
Mail: [ | ||
{ name: 'from', type: 'Person' }, | ||
{ name: 'to', type: 'Person' }, | ||
{ name: 'contents', type: 'string' } | ||
] | ||
}, | ||
primaryType: 'Mail', | ||
message: { | ||
from: { | ||
name: 'Cow', | ||
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' | ||
}, | ||
to: { | ||
name: 'Bob', | ||
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB' | ||
}, | ||
contents: 'Hello, Bob!' | ||
} | ||
} | ||
|
||
it('should validate a valid SignTypedDataAction object', () => { | ||
const validAction = { | ||
action: Action.SIGN_TYPED_DATA, | ||
nonce: 'xxx', | ||
resourceId: 'resourceId', | ||
typedData | ||
} | ||
|
||
const result = SignTypedDataAction.safeParse(validAction) | ||
|
||
expect(result).toEqual({ | ||
success: true, | ||
data: expect.any(Object) | ||
}) | ||
}) | ||
|
||
it('should validate a valid typedData as a string', () => { | ||
const validAction = { | ||
action: Action.SIGN_TYPED_DATA, | ||
nonce: 'xxx', | ||
resourceId: 'resourceId', | ||
typedData: JSON.stringify(typedData) | ||
} | ||
|
||
const result = SignTypedDataAction.safeParse(validAction) | ||
|
||
expect(result.success).toEqual(true) | ||
}) | ||
|
||
it('should validate a valid typedData as a hex-encoded stringified json object', () => { | ||
const validAction = { | ||
action: Action.SIGN_TYPED_DATA, | ||
nonce: 'xxx', | ||
resourceId: 'resourceId', | ||
typedData: toHex(JSON.stringify(typedData)) | ||
} | ||
|
||
const result = SignTypedDataAction.safeParse(validAction) | ||
|
||
expect(result.success).toEqual(true) | ||
}) | ||
|
||
it('should not validate an invalid SignTypedDataAction object with invalid JSON string', () => { | ||
const invalidAction = { | ||
action: Action.SIGN_TYPED_DATA, | ||
nonce: 'xxx', | ||
resourceId: 'resourceId', | ||
typedData: 'invalidJSON' | ||
} | ||
|
||
const result = SignTypedDataAction.safeParse(invalidAction) | ||
|
||
expect(result.success).toEqual(false) | ||
}) | ||
}) |
74 changes: 0 additions & 74 deletions
74
packages/policy-engine-shared/src/lib/schema/action.schema.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.