mirror of
https://github.com/eosnetworkfoundation/mandel-eosjs.git
synced 2026-07-21 14:33:28 +00:00
Merge pull request #46 from eosnetworkfoundation/ehp/GH-29-bignumber-int
Serialization Tests and git workflow
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
name: checkin-actions
|
||||
on:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x 19.x]
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
- run: npm run test
|
||||
- run: npm run test-serialization
|
||||
Generated
+222
-10300
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -9,8 +9,9 @@
|
||||
"prepare": "npm run build",
|
||||
"lint": "eslint --ext .js,.jsx,.ts,.tsx src",
|
||||
"test": "jest src/tests/*eosjs*",
|
||||
"test-serialization": "jest src/tests/serialization.test.ts",
|
||||
"test-node": "jest src/tests/*node*",
|
||||
"test-all": "yarn test && yarn test-node && yarn cypress",
|
||||
"test-all": "yarn test && yarn test-node && yarn test-serialization && yarn cypress",
|
||||
"build": "tsc -p ./tsconfig.json && cp src/ripemd.es5.js dist/ripemd.js",
|
||||
"build-web": "webpack --config webpack.prod.js && webpack --config webpack.debug.js",
|
||||
"build-production": "yarn build && yarn build-web && yarn test-all",
|
||||
|
||||
@@ -345,6 +345,10 @@ export class SerialBuffer { // tslint:disable-line max-classes-per-file
|
||||
}
|
||||
|
||||
/** Get a `name` */
|
||||
// 13th character of a name must be 'j' or lower
|
||||
// If you try 'zzzzzzzzzzzzz', it maxes out byte array 'FFFFFFFFFFFFFFFF'
|
||||
// The extra bits for 13th 'z' are dropped
|
||||
// turing the last 'z' into an 'j'
|
||||
public getName() {
|
||||
const a = this.getUint8Array(8);
|
||||
let result = '';
|
||||
@@ -364,6 +368,7 @@ export class SerialBuffer { // tslint:disable-line max-classes-per-file
|
||||
result += '.';
|
||||
}
|
||||
}
|
||||
// removals all trailing dots
|
||||
while (result.endsWith('.')) {
|
||||
result = result.substr(0, result.length - 1);
|
||||
}
|
||||
|
||||
+2310
-29
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
||||
import { TextDecoder, TextEncoder } from 'text-encoding';
|
||||
import * as ser from "../eosjs-serialize";
|
||||
import {SerialBuffer} from "../eosjs-serialize";
|
||||
const transactionAbi = require('../transaction.abi.json');
|
||||
|
||||
// setup shared buffer re-established before every test
|
||||
let buffer: SerialBuffer;
|
||||
describe('Strict Deserialization Tests', () => {
|
||||
let textEncoder = new TextEncoder();
|
||||
let textDecoder = new TextDecoder();
|
||||
let transactionType: Map<string, ser.Type> = ser.getTypesFromAbi(ser.createInitialTypes(), transactionAbi);
|
||||
|
||||
beforeEach( () => {
|
||||
buffer = new ser.SerialBuffer({
|
||||
textEncoder: textEncoder,
|
||||
textDecoder: textDecoder,
|
||||
});
|
||||
});
|
||||
|
||||
it('out of range int8 128', () => {
|
||||
expect (() => {
|
||||
const hex = "80";
|
||||
const type = "int8";
|
||||
buffer.pushArray(ser.hexToUint8Array(hex));
|
||||
const thisType = ser.getType(transactionType, type);
|
||||
const testValue: number = thisType.deserialize(buffer);
|
||||
expect(testValue).toBeTruthy();
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('out of range int8 -129', () => {
|
||||
expect ( () => {
|
||||
const hex = "7FFF";
|
||||
const expected = "-129";
|
||||
const type = "int8";
|
||||
buffer.pushArray(ser.hexToUint8Array(hex));
|
||||
const thisType = ser.getType(transactionType, type);
|
||||
const testValue: number = thisType.deserialize(buffer);
|
||||
expect(expected).toBeTruthy();
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('out of range uint8 256', () => {
|
||||
expect ( () => {
|
||||
const hex = "0001";
|
||||
const expected = "256";
|
||||
const type = "uint8";
|
||||
buffer.pushArray(ser.hexToUint8Array(hex));
|
||||
const testValue = transactionType.get(type).deserialize(buffer);
|
||||
expect(expected).toBeTruthy();
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user