Giter Club home page Giter Club logo

as's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

as's Issues

ByteArray.toByteString for numbers return empty string

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?

Test AS and TS version of serializer

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

Create a Good readme - AS

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

  • Readme should have a better onboarding for SC-devs to using our AS libraries and tools.
  • It should also contain descriptions of components, as well as how we handle the releases (short description).

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:

  • set the lint configuration
  • fix all typedoc
  • deploy the html type-doc
  • write the readme for as-transformer

Fix Amount

  • Remove invalid and use result object instead
  • Change serialize/deserialize

Fix currency

  • Remove invalid and use result object instead
  • Change serialize/deserialize

Create issue templates

  • bug template based on Thyra repo
  • task template based on Thyra repo

QA testing

  1. Once merged, click on "New issue" button
  2. You will be able to see both templates ready-to-use

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 :)

Deprecate Valider

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

  • deprecate it

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

create package as-types

The idea is to transform massa/as to a group a multiple independant repos.

We should create as-type and migrate there:

  • amount
  • currency
  • result

Envy fails to run on Windows

On Windows, the tester cli fails to run ( yarn asctester ) because it cannot find the :

  • bootstrap.js
  • unitttest.ts
    The error displays that paths of both file are something like :

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.

Improve SafeMath

Context

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

Proper way to serialize and deserialize

Context
Massa SC runtime can only pass one argument to our sc functions. So we need to serialize sc call arguments.

  • Currently, we use Args class.
  • We also use Args to convert types
  • We also use toBytes/fromBytes helper function.

The goal is to uniform the way we serialize/de-serialize that data

Use cases:

  • function arguments
  • sc datastore
  • function return value

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

  • move toBytes/fromBytes from massa-as-sdk to as-types utils.
  • use toBytes/fromBytes and utils in Args
  • remove ByteArray
  • rename Args into Serde
  • document our new best practices:
    • return value: utils
    • return multiple values: Args
    • function argument: Args
    • Storage: on value: utils
    • Storage: multiple values: Args

Create a good ReadMe AS-TYPES

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.

  • This will be done by adding in the readme a link to the generate typedoc documentation website

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:

create as-proba

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.

Args: With strings cause failure

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.

Create an assemblyscript transfomer to do Args deserialization of argument

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

  • add a new transformer
  • define and create the function signature that the transformer will match

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

Serialize arrays

Context

We want to be able to serialize arrays

How to

  • serialize array of any type with a template parameter
  • add unit test for u64

Create a SafeMath Library ( Addition & Substraction)

Context

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

How to

We need to create a library (or better find an existing one) that handles overflow & underflow on :

  • Addition
  • Subtraction
  • multiplication
  • division
  • modulo

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

Serde 16 intergers

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:

  • u16toBtes
  • bytesTou16

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

Use a monorepo manager tool

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:

  • compiling the typescripts sub-packages: the script "npm run build" should do somehing like "lerna build"
  • publishing the packages on npm using 'lerna publish' (maybe done in another issue)

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

Add protobuf transformer

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 :

  • create the proto file - #109
  • generate helpers - #164
  • create the wrapping function SayHello - #114
  • replace the SC with the updated one and load all dependencies - #132

Create a good ReadMe AS-PROBA

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:

Remove tester and update test transformer to target as-pect

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:

  • the if statement generation where is, isNot, isFalse, isTrue shall be replaced with the correct as-pect test expression (toBe in the code above)
  • the test code generation
  • the entire logic of how to handle test failure (TestResult.Success, TestResult.Failure, TestResult.StopTestSet). Right now stopping the entire test (StopTestSet) wasn't really used so in this task we should focus on simply remove all that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.