-
Notifications
You must be signed in to change notification settings - Fork 16
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
Showing
17 changed files
with
171 additions
and
14 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,9 @@ | ||
// @flow | ||
|
||
declare module 'deasync' { | ||
declare module.exports: { | ||
loopWhile: (fn: () => boolean) => void; | ||
runLoopOnce: () => void; | ||
sleep: (ms: number) => void; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// ISC, Copyright 2017-2018 Jaco Greeff | ||
/* eslint camelcase: 0 */ | ||
|
||
const index = require('./index'); | ||
|
||
describe('set_storage', () => { | ||
let heap; | ||
let storage; | ||
let set_storage; | ||
|
||
beforeEach(() => { | ||
const uint8 = new Uint8Array([0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f]); | ||
|
||
heap = { | ||
get: (ptr, len) => uint8.subarray(ptr, ptr + len) | ||
}; | ||
|
||
storage = { | ||
put: jest.fn((key, value) => Promise.resolve(true)) | ||
}; | ||
|
||
set_storage = index({ heap, storage }).set_storage; | ||
}); | ||
|
||
it('sets the value into storage', () => { | ||
set_storage(0, 3, 3, 5); | ||
|
||
expect( | ||
storage.put | ||
).toHaveBeenCalledWith('Say', Buffer.from('Hello')); | ||
}); | ||
}); |
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
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
// ISC, Copyright 2017-2018 Jaco Greeff | ||
// @flow | ||
|
||
const deasync = require('deasync'); | ||
|
||
const isError = require('@polkadot/util/is/error'); | ||
const isUndefined = require('@polkadot/util/is/undefined'); | ||
|
||
// FIXME: This is currently for Node environments only - for Browser environments deasync is not available, we need a different solution. Once available, could move to @polkadot/util | ||
// flowlint-next-line unclear-type:off | ||
module.exports = function syncify (promise: Promise<any>): any { | ||
let result; | ||
|
||
promise | ||
.catch((error) => error) | ||
.then((_result) => { | ||
result = _result; | ||
}); | ||
|
||
let ms = 0; | ||
|
||
while (isUndefined(result)) { | ||
deasync.sleep(ms++); | ||
} | ||
|
||
if (isError(result)) { | ||
throw result; | ||
} | ||
|
||
return result; | ||
}; |
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,25 @@ | ||
// ISC, Copyright 2017-2018 Jaco Greeff | ||
|
||
const syncify = require('./syncify'); | ||
|
||
describe('syncify', () => { | ||
it('returns the result of the promise', () => { | ||
expect( | ||
syncify( | ||
new Promise((resolve) => { | ||
setTimeout(() => resolve(12345), 100); | ||
}) | ||
) | ||
).toEqual(12345); | ||
}); | ||
|
||
it('throws promise exceptions', () => { | ||
expect( | ||
() => syncify( | ||
new Promise((resolve, reject) => { | ||
setTimeout(() => reject(new Error('test reject error')), 100); | ||
}) | ||
) | ||
).toThrow(/test reject error/); | ||
}); | ||
}); |
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,10 @@ | ||
// ISC, Copyright 2017-2018 Jaco Greeff | ||
// @flow | ||
|
||
require('./polyfill'); | ||
|
||
const decoder = new TextDecoder('utf-8'); | ||
|
||
module.exports = function utf8Decode (u8a: Uint8Array): string { | ||
return decoder.decode(u8a); | ||
}; |
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,15 @@ | ||
// ISC, Copyright 2017-2018 Jaco Greeff | ||
|
||
const utf8Decode = require('./utf8Decode'); | ||
|
||
describe('utf8Decode', () => { | ||
const TEST = 'Привет, мир!'; | ||
|
||
it('decodes the buffer correctly', () => { | ||
expect( | ||
utf8Decode( | ||
new TextEncoder('utf-8').encode(TEST) | ||
) | ||
).toEqual(TEST); | ||
}); | ||
}); |
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,15 @@ | ||
// ISC, Copyright 2017-2018 Jaco Greeff | ||
// @flow | ||
|
||
export type WasmExports = { | ||
// flowlint-next-line unclear-type:off | ||
env: Object | ||
}; | ||
|
||
export type WasmConfigType = { | ||
memoryInitial: number, | ||
memoryMaximum: number | ||
}; | ||
|
||
// flowlint-next-line unclear-type:off | ||
export type WasmExtraImports = Object; |
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