massalabs / as Goto Github PK
View Code? Open in Web Editor NEWMassa Labs assembly script repo
License: MIT License
Massa Labs assembly script repo
License: MIT License
Make PR for repos that depends on @massalabs/as to update AS+aspect..
In this PR massalabs/massa-as-sdk#23 I try to create an Args class that handle the encoding and decoding of function call arguments.
The problem is that I can't make the current code work.
const ADDR1 = 'A1Czd9sRp3mt2KU9QBEEZPsYxRq9TisMs1KnV4JYCe7Z4AAVinq';
const ADDR2 = 'A1cjz8wvMvShrBH5eqGYkuFGGncTNqszJc1BDKwR7oou8fpLD2E';
const ENCODED =
'3A1Czd9sRp3mt2KU9QBEEZPsYxRq9TisMs1KnV4JYCe7Z4AAVinq3A1cjz8wvMvShrBH5eqGYkuFGGncTNqszJc1BDKwR7oou8fpLD2Ed';
describe('Args tests', () => {
it('encode, old way', () => {
const ownerAccount = new Address(ADDR1);
const recipientAccount = new Address(ADDR2);
const nbTokens = new Amount(100);
const result = ownerAccount
.toStringSegment()
.concat(
recipientAccount
.toStringSegment()
.concat(ByteArray.fromU64(nbTokens.value()).toByteString()),
);
expect(result).toBe(ENCODED); // broken
});
it('decode, old way', () => {
const args = ENCODED;
const ownerAddress = new Address();
let offset = ownerAddress.fromStringSegment(args);
const recipientAddress = new Address();
offset = recipientAddress.fromStringSegment(args, offset);
const amount = ByteArray.fromByteString(args.substr(offset, 8)).toU64();
expect(ownerAddress._value).toBe(ADDR1);
expect(recipientAddress._value).toBe(ADDR2);
expect(amount.toString()).toBe('100'); // broken
});
});
Because ByteArray.fromU64
creates a Byte Array with value 1 and in toByteString
, String.fromCharCode(1);
returns an empty string according to this https://asecuritysite.com/coding/asc2
I might misunderstood something, could anyone help me on this please?
Context
The argument class as evolved and is not compatible anymore with the Args class in Typescript from massa-web3.
Another issue will be created in web3 repo to fix this.
This issue is about detection of such differences between the assemblyscript and the typescript version of Args.
Proposed solution
Import massa-web3 lib as dev dependency and use it to generate a file containing both serialized and not serialized values for each types. For convenient use, this file can be commited, alongside its generation script. This file will be used as input for testing serializer in assemblyscript.
This solution is not perfect but it will allow us to detect a breaking change made in the AS side.
The drawback is to detect a breaking change in the TS side, the massa-web3 lib must be updated and the testfile, regenerated
Prerequisite
The context:
AS is a monorepo containing separate packages that provide functionalities for AS. It is poor and does not explain what each of the packages are meant for.
Very good starting reference for readme is massa-web3 one: https://github.com/massalabs/massa-web3
The need
How-to:
TypeDocs can generate the documentation of our tooling packages.
We will have to maintain the Readme manually and add a link to the generated html documentation.
Therefore, with each new feature and important improvements, the requirement will be updating the typedoc in the source code of the repo.
Tech details:
QA testing
To go further, if you need to change these template. You can go to:
On this repo > code section > .github folder > ISSUE_TEMPLATE folder > you'll see both template and will be able to edit them as you wish :)
Originally posted by @Thykof in #90 (comment)
for as-types Amount and Currency classes
following massalabs/massa-as-sdk#16 and the test table for envy test, we will be able to use test table to add more test and keep some demonstrative tests (with comments and how-to use guide).
This issue is blocked by massalabs/massa-as-sdk#29
tasks:
Context
Describe / explain why we should do this: motivations, context or other info. Keep it brief and simple - PM
Coming from massalabs/massa-as-sdk#145 (comment)
The Valider
interface is no longer useful.
User flow
Describe the user flow using user stories so the end result is super clear - PM
How to
List the step-by-step to get it do if needed - PM
Technical details
Give the technical insights so anyone in the team can tackle the tasks - Dev
QA testing
Does this task require some QA tests ?
If yes, explain how to validate it
The idea is to transform massa/as to a group a multiple independant repos.
We should create as-type and migrate there:
On Windows, the tester
cli fails to run ( yarn asctester
) because it cannot find the :
bootstrap.js
unitttest.ts
C:\Users\maxim\projetsInfo\Blockchain\Massa\jj\node_modules\tester\lib\bootstrap.js
Error: Cannot find module 'C:\C:\Users\maxim\projetsInfo\Blockchain\Massa\jj\node_modules\tester\lib\bootstrap.js'
Working well on Mac, not tested on Linux.
Describe / explain why we should do this: motivations, context or other info. Keep it brief and simple - PM
This pull request #101 has been merge to fix the CI (code formatting) and the code review by Greg is interesting.
This issue is about trying to improve the SafeMath functions.
User flow
Describe the user flow using user stories so the end result is super clear - PM
How to
List the step-by-step to get it do if needed - PM
Technical details
Give the technical insights so anyone in the team can tackle the tasks - Dev
QA testing
Does this task require some QA tests ?
If yes, explain how to validate it
Context
Massa SC runtime can only pass one argument to our sc functions. So we need to serialize sc call arguments.
The goal is to uniform the way we serialize/de-serialize that data
Use cases:
Research
The package as-buffer
of this repo performs serialization and de-serialization: https://github.com/ask-lang/serde-as. But the offset is reset to 0 at each read. So we need our Args
to concatenate values.
The package as-serde
provide decorator and transformer to serialize/de-serialize classes. This can be very useful for our custom classes (for function arguments, objects stored into the sc datastore...)
How to
toBytes
/fromBytes
from massa-as-sdk
to as-types
utils.toBytes
/fromBytes
and utils in Args
ByteArray
Args
into Serde
Prerequisite
The context:
As-types has a poor readme.
Very good starting reference for readme is massa-web3 one: https://github.com/massalabs/massa-web3
The need
Readme should explain all classes, and best practices that involve the usage of as-types.
How-to:
TypeDocs can generate the documentation of our packages.
Therefore, with each new feature and improvements, the requirement will be updating the typedoc of the source code of the repo.
Tech details:
The idea is to transform massa/as to a group a multiple independant repos.
We should create as-proba and migrate there the math/probability directory.
During our GGH hackathon a team had a smart contract with args that contains 6 strings and this was running it in an autonomous SC but when he deployed his SC he had the bytecode error Unreachable
.
He replaced the args system by his own parsing that was with separator in the string and he didn't had error anymore. Sadly I wasn't able to ask him to send me the code as he was just to time to finish his project before the deadline.
I think we should try to reproduce it before mark it as a real bug.
Context
Describe / explain why we should do this: motivations, context or other info. Keep it brief and simple - PM
User flow
Describe the user flow using user stories so the end result is super clear - PM
How to
List the step-by-step to get it do if needed - PM
Technical details
Give the technical insights so anyone in the team can tackle the tasks - Dev
for example we would like to transform:
export function greetings(arguments(firstArg: string, secondArg: i32)) {...}
into:
export function greetings(_args: StaticArray<u8>) {
const args = new Args(_args);
const firstArg: string = args.nextString().expect('argument 1 is invalid');
const secondArg: i32 = args.nextI32().expect('argument 2 is invalid');
...
}
QA testing
Does this task require some QA tests ?
If yes, explain how to validate it
We would like new types in the Args class to use them in our smart contracts.
The types we need are:
Dusa project is requesting the following types:
We want to be able to serialize arrays
Math operation on computer could go wrong because of the maximum value that a number can take.
Example: if you add to number with each value is MAX_VALUE, you can't have a correct result, this is called an overflow (it goes beyong). Same thing appear when substracting bellow the minimum value.
(MAX_VALUE being the maximum value a number can take in a computer, because its not infinite like in real math)
In ethereum, OpenZeppelin developed a bunch of function to handle this: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol
We need to create a library (or better find an existing one) that handles overflow & underflow on :
Also write unit tests.
These functions must not assert
but rather return a Result
This existing library is WIP https://github.com/MaxGraey/as-bignum/tree/master/assembly/integer/safe
Existing SafeMath library of another blockchain that uses a custom 'Result'-like return type (SafeInteger): https://github.com/koinos/koinos-sdk-as/blob/master/assembly/util/safeMath.ts
Add a way to convert StaticArray to string and vice-versa
Context
Describe / explain why we should do this: motivations, context or other info. Keep it brief and simple - PM
User flow
Describe the user flow using user stories so the end result is super clear - PM
How to
List the step-by-step to get it do if needed - PM
Add helpers in serialization/numbers.ts:
Add Args.nextU16() that use the created helpers
Technical details
Give the technical insights so anyone in the team can tackle the tasks - Dev
QA testing
Does this task require some QA tests ?
If yes, explain how to validate it
In order to properly manage @massalabs/as monorepo and to prepare potentially new subpackages we should use a monorepo manager tool.
Update:
Lerna is no longe maintained. Thus we will npm workspace for now.
The technical details beside are still valid and must be adapted to npm workspace
Lerna documentation is here:
https://lerna.js.org/
Lerna can do a lot of stuff but here we will focus on 2 things:
all sub packages should be placed in a "packages" folder
There should be plenty of example of using lerna but you can look at the as-pect repo to have a simple example:
https://github.com/as-pect/as-pect
assert(1==2, msg) return abort buffer is not defined instead of msg
The idea is for an end user to be able to write function such as:
@exportAs("SayHello")
function _sayHello(language: string, name: string): string {
let salute = 'Hello'; + language;
if (language == "french") {
salute = "Bonjour";
}
return `${salut}, ${name}!`;
}
And that the transformer :
Prerequisite
The context:
As-proba has a poor readme.
Very good starting reference for readme is massa-web3 one: https://github.com/massalabs/massa-web3
The need
Readme should explain all mathematic and probabilistic classes and functions, and best practices that involve the usage of those.
How-to:
TypeDocs can generate the documentation of our packages. The readme will contain a link to the generated documentation
Therefore, with each new feature an improvements, the requirement will be updating the typedoc of the source code of the repo.
Tech details:
Following the creation of class Result.
Inspired by https://doc.rust-lang.org/std/option/enum.Option.html
modify CLI to be able to use --exportRuntime functions in function inside the --import file
When used, the transformer generates the following code:
test('sum of two integers', ():i32 => {
const got = 1 + 2;
const want = 4;
if (got != want) {
error('1 + 2 = ' + got.toString() + ', ' + want.toString() + ' was expected.');
return TestResult.Failure;
}
return TestResult.Success;
});
We should modify this to get something like:
test('sum of two integers', () => {
const got = 1 + 2;
const want = 4;
expect(got).toBe(want, '1 + 2 = ' + got.toString() + ', ' + want.toString() + ' was expected.');
});
This will imply to modify:
is
, isNot
, isFalse
, isTrue
shall be replaced with the correct as-pect test expression (toBe
in the code above)We should do the same as in https://github.com/massalabs/massa-as-sdk/tree/main/.github/workflows
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.