Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve lisk-codec protocol specs to be more deterministic #6589

Closed
Tracked by #6653
nazarhussain opened this issue Jul 19, 2021 · 0 comments · Fixed by #6650
Closed
Tracked by #6653

Improve lisk-codec protocol specs to be more deterministic #6589

nazarhussain opened this issue Jul 19, 2021 · 0 comments · Fixed by #6650

Comments

@nazarhussain
Copy link
Contributor

Description

The protocol specs of any component in the system must be deterministic, means input and output must defined explicitly for every case. And there must not be any modifications/mutations to output/input runtime to pass the tests.

Currently we have protocol specs for lisk-codec encoding behaviour, but we don't have it for decoding behaviour. And as per our implementation of lisk-codec and by specification of the LIP the encoding and decoding may not turn out be same as always. e.g. Its a viable chance that in example below data and reverseData may not match strictly because of the default values for properties which are not defined in the data object.

const data = {a: 1, b: 2}
const binary = codec.encode(schema, data);
const reverseData = codec.decode(schema, binary);

To cover this part we had a lot of custom manipulation of protocol specs in test suites, which does not fulfil the purpose of having protocol specs. e.g. few of reference mentioned below. We need to improve these and protocol specs must define the decoding specs and we should avoid runtime mutation of specs input/output in our tests

expect(result).toEqual({
...testCase.input.object,
number: BigInt(testCase.input.object.number),
});
});

expect(result).toEqual({
...testCase.input.object,
balance: BigInt(testCase.input.object.balance),
address: Buffer.from(testCase.input.object.address?.data as number[]),
});

expect(result).toEqual({
...testCase.input.object,
myArray: testCase.input.object.myArray?.map(l => ({
...l,
amount: BigInt(l.amount),
})),
});

Motivation

The protocol specs for Lisk-Codec must deterministic and cover both encoding and decoding behaviours.

Additional Information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants