-
Notifications
You must be signed in to change notification settings - Fork 20
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
James Zheng
committed
Jul 6, 2022
1 parent
8fb3f0a
commit 6a271c9
Showing
1 changed file
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as oasisRT from './../src'; | ||
import * as nacl from 'tweetnacl'; | ||
|
||
describe('callformat', () => { | ||
describe('encodeCall/DecodeResult', () => { | ||
it('Should encode and decode the message correctly', () => { | ||
const message = "I will find some random message here" | ||
const pairs = nacl.box.keyPair() | ||
const publicKey = pairs.publicKey | ||
const rawCall: oasisRT.types.Call = { | ||
format: oasisRT.transaction.CALLFORMAT_ENCRYPTED_X25519DEOXYSII, | ||
method: '', | ||
body: message | ||
} | ||
const dummy = new Uint8Array() | ||
const keyManagerPk: oasisRT.types.KeyManagerSignedPublicKey = { | ||
key: publicKey, | ||
checksum: dummy, | ||
signature: dummy | ||
} | ||
const config: oasisRT.callformat.EncodeConfig = { | ||
publicKey: keyManagerPk | ||
} | ||
const [sealedCall, meta] = oasisRT.callformat.encodeCall(rawCall, oasisRT.transaction.CALLFORMAT_ENCRYPTED_X25519DEOXYSII, config) | ||
|
||
const fakedResult: oasisRT.types.CallResult = { | ||
unknown: sealedCall.body as Uint8Array | ||
} | ||
|
||
var decodedResult = oasisRT.callformat.decodeResult(fakedResult, oasisRT.transaction.CALLFORMAT_ENCRYPTED_X25519DEOXYSII, meta as oasisRT.callformat.MetaEncryptedX25519DeoxysII) as oasisRT.types.Call | ||
expect(decodedResult.body).toEqual(message) | ||
}); | ||
}); | ||
}); |