Skip to content

Commit

Permalink
add the callformat unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
James Zheng committed Jul 6, 2022
1 parent 8fb3f0a commit 6a271c9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions client-sdk/ts-web/rt/test/callformat.test.ts
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)
});
});
});

0 comments on commit 6a271c9

Please sign in to comment.