koinos / koinos-sdk-as

AssemblyScript (AS) Software Development Toolkit (SDK) for the Koinos Blockchain
https://roaminroe.github.io/koinos-as-sdk/
MIT License
5 stars 3 forks source link

As v0.2x.x #71

Closed roaminro closed 1 year ago

roaminro commented 1 year ago

Brief description

AS v0.20 introduces breaking changes, this PR updates everything that is needed in order to compile the SDK with AS v0.2x.x

This PR depends on 2 other PRs: https://github.com/koinos/as-proto/pull/13 https://github.com/koinos/koinos-proto-as/pull/9

Checklist

Demonstration

 AS-pect⚡ Test suite runner [8.0.1]
Using config: /home/rr/Documents/blockchain/koinos-sdk-as/as-pect.config.js
ASC Version: 0.25.1
[Log]Using code coverage: assembly/*.ts, assembly/util/*.ts
[Log]Using coverage: assembly/*.ts, assembly/util/*.ts
[Describe]: MockVM

 [Success]: ✔ should get the chain id
 [Success]: ✔ should set the contract arguments
 [Success]: ✔ should set the contract id
 [Success]: ✔ should set the head info
 [Success]: ✔ should set the last irreversible block
 [Success]: ✔ should set the caller
 [Success]: ✔ should set the transaction
 [Success]: ✔ should set the operation
 [Success]: ✔ should set the block
 [Success]: ✔ should set the authorities
 [Success]: ✔ should set the call contract results
 [Success]: ✔ should reset the MockVM database
 [Success]: ✔ should handle transactions
[Log] log 1
[Log] log 2
[Log] log 3
 [Success]: ✔ should handle logs
 [Success]: ✔ should handle error messages
 [Success]: ✔ should set verify vrf proof results
 [Success]: ✔ should set system authority

    [File]: __tests__/mockVM.spec.ts
  [Groups]: 2 pass, 2 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 17 pass,  0 fail, 17 total
    [Time]: 245.876ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Describe]: tryAdd

 [Success]: ✔ adds correctly
 [Success]: ✔ adds correctly - u128
 [Success]: ✔ reverts on addition overflow
 [Success]: ✔ reverts on addition overflow - u128
 [Success]: ✔ adds correctly if it does not overflow and the result is positive
 [Success]: ✔ adds correctly if it does not overflow and the result is negative
 [Success]: ✔ reverts on positive addition overflow
 [Success]: ✔ reverts on negative addition overflow

[Describe]: add

 [Success]: ✔ adds correctly
 [Success]: ✔ adds correctly - u128
[Contract Exit] could not add 18446744073709551615 to 1
[Contract Exit] could not add 1 to 18446744073709551615
 [Success]: ✔ reverts on addition overflow
[Contract Exit] could not add
[Contract Exit] could not add
 [Success]: ✔ reverts on addition overflow - u128
 [Success]: ✔ adds correctly if it does not overflow and the result is positive
 [Success]: ✔ adds correctly if it does not overflow and the result is negative
[Contract Exit] could not add 9223372036854775807 to 1
[Contract Exit] could not add 1 to 9223372036854775807
 [Success]: ✔ reverts on positive addition overflow
[Contract Exit] could not add -9223372036854775808 to -1
[Contract Exit] could not add -1 to -9223372036854775808
 [Success]: ✔ reverts on negative addition overflow
[Contract Exit] my message
[Contract Exit] my message1
[Contract Exit] my message2
 [Success]: ✔ reverts with a custom message

[Describe]: trySub

 [Success]: ✔ subtracts correctly
 [Success]: ✔ subtracts correctly - u128
 [Success]: ✔ reverts if subtraction result would be negative
 [Success]: ✔ reverts if subtraction result would be negative - u128
 [Success]: ✔ subtracts correctly if it does not overflow and the result is positive
 [Success]: ✔ subtracts correctly if it does not overflow and the result is negative
 [Success]: ✔ reverts on positive subtraction overflow
 [Success]: ✔ reverts on negative subtraction overflow

[Describe]: sub

 [Success]: ✔ subtracts correctly
 [Success]: ✔ subtracts correctly - u128
[Contract Exit] could not subtract 5678 from 1234
 [Success]: ✔ reverts if subtraction result would be negative
[Contract Exit] could not subtract
 [Success]: ✔ reverts if subtraction result would be negative - u128
 [Success]: ✔ subtracts correctly if it does not overflow and the result is positive
 [Success]: ✔ subtracts correctly if it does not overflow and the result is negative
[Contract Exit] could not subtract -1 from 9223372036854775807
 [Success]: ✔ reverts on positive subtraction overflow
[Contract Exit] could not subtract 1 from -9223372036854775808
 [Success]: ✔ reverts on negative subtraction overflow
[Contract Exit] my message
[Contract Exit] my message1
 [Success]: ✔ reverts with a custom message

[Describe]: tryMul

 [Success]: ✔ multiplies correctly
 [Success]: ✔ multiplies correctly - u128
 [Success]: ✔ multiplies correctly - signed integers
 [Success]: ✔ multiplies by zero correctly
 [Success]: ✔ multiplies by zero correctly - u128
 [Success]: ✔ multiplies by zero correctly - signed integers
 [Success]: ✔ reverts on multiplication overflow
 [Success]: ✔ reverts on multiplication overflow - u128
 [Success]: ✔ reverts on multiplication overflow, positive operands
 [Success]: ✔ reverts when minimum integer is multiplied by -1 - i64
 [Success]: ✔ reverts when minimum integer is multiplied by -1 - i32
 [Success]: ✔ reverts when minimum integer is multiplied by -1 - i16
 [Success]: ✔ reverts when minimum integer is multiplied by -1 - i8

[Describe]: mul

 [Success]: ✔ multiplies correctly
 [Success]: ✔ multiplies correctly - u128
 [Success]: ✔ multiplies by zero correctly
 [Success]: ✔ multiplies by zero correctly - u128
[Contract Exit] could not multiply
[Contract Exit] could not multiply
 [Success]: ✔ reverts on multiplication overflow - u128
[Contract Exit] could not multiply 9223372036854775807 by 2
[Contract Exit] could not multiply 2 by 9223372036854775807
 [Success]: ✔ reverts on multiplication overflow
[Contract Exit] my message
[Contract Exit] my message1
 [Success]: ✔ reverts on multiplication overflow with a custom message

[Describe]: tryDiv

 [Success]: ✔ divides correctly
 [Success]: ✔ divides correctly - u128
 [Success]: ✔ divides correctly - signed integers
 [Success]: ✔ divides zero correctly
 [Success]: ✔ divides zero correctly - u128
 [Success]: ✔ divides zero correctly - signed integers
 [Success]: ✔ returns complete number result on non-even division
 [Success]: ✔ returns complete number result on non-even division - u128
 [Success]: ✔ returns complete number result on non-even division - signed integers
 [Success]: ✔ reverts on division by zero
 [Success]: ✔ reverts on division by zero - u128
 [Success]: ✔ reverts on division by zero - signed integers
 [Success]: ✔ reverts on overflow, negative second - i64
 [Success]: ✔ reverts on overflow, negative second - i32
 [Success]: ✔ reverts on overflow, negative second - i16
 [Success]: ✔ reverts on overflow, negative second - i8

[Describe]: div

 [Success]: ✔ divides correctly
 [Success]: ✔ divides correctly - u128
 [Success]: ✔ divides zero correctly
 [Success]: ✔ divides zero correctly - u128
 [Success]: ✔ returns complete number result on non-even division
 [Success]: ✔ returns complete number result on non-even division - u128
[Contract Exit] could not divide 5678 by 0
 [Success]: ✔ reverts on division by zero
[Contract Exit] could not divide
 [Success]: ✔ reverts on division by zero - u128
[Contract Exit] my message
[Contract Exit] my message1
 [Success]: ✔ reverts on division by zero with a custom message

[Describe]: trymod

[Describe]: modulos correctly

 [Success]: ✔ when the dividend is smaller than the divisor
 [Success]: ✔ when the dividend is smaller than the divisor - u128
 [Success]: ✔ when the dividend is smaller than the divisor - signed integers
 [Success]: ✔ when the dividend is equal to the divisor
 [Success]: ✔ when the dividend is equal to the divisor - u128
 [Success]: ✔ when the dividend is equal to the divisor - signed integers
 [Success]: ✔ when the dividend is larger than the divisor
 [Success]: ✔ when the dividend is larger than the divisor - u128
 [Success]: ✔ when the dividend is larger than the divisor - signed integers
 [Success]: ✔ when the dividend is a multiple of the divisor
 [Success]: ✔ when the dividend is a multiple of the divisor - u128
 [Success]: ✔ when the dividend is a multiple of the divisor - signed integers

 [Success]: ✔ reverts with a 0 divisor
 [Success]: ✔ reverts with a 0 divisor - u128
 [Success]: ✔ reverts with a 0 divisor - signed integers
 [Success]: ✔ reverts on overflow, negative second - i64
 [Success]: ✔ reverts on overflow, negative second - i32
 [Success]: ✔ reverts on overflow, negative second - i16
 [Success]: ✔ reverts on overflow, negative second - i8

[Describe]: mod

[Describe]: modulos correctly

 [Success]: ✔ when the dividend is smaller than the divisor
 [Success]: ✔ when the dividend is smaller than the divisor - u128
 [Success]: ✔ when the dividend is equal to the divisor
 [Success]: ✔ when the dividend is equal to the divisor - u128
 [Success]: ✔ when the dividend is larger than the divisor
 [Success]: ✔ when the dividend is larger than the divisor - u128
 [Success]: ✔ when the dividend is a multiple of the divisor
 [Success]: ✔ when the dividend is a multiple of the divisor - u128

[Contract Exit] could not calulate 5678 modulo 0
 [Success]: ✔ reverts with a 0 divisor
[Contract Exit] could not calulate modulo
 [Success]: ✔ reverts with a 0 divisor - u128
[Contract Exit] my message
 [Success]: ✔ reverts with a 0 divisor with a custom message
[Contract Exit] my message
 [Success]: ✔ reverts with a 0 divisor with a custom message - u128

    [File]: __tests__/safeMath.spec.ts
  [Groups]: 14 pass, 14 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 110 pass,  0 fail, 110 total
    [Time]: 1159.902ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Describe]: storage

 [Success]: ✔ should put and get an object in a Map
 [Success]: ✔ should get an object in a Map with default value
 [Success]: ✔ should check if storage has an object or not
 [Success]: ✔ should remove an object
 [Success]: ✔ should get next and prev object
 [Success]: ✔ should get many

[Describe]: storage with proto key

 [Success]: ✔ should put and get an object
 [Success]: ✔ should check if storage has an object or not
 [Success]: ✔ should remove an object
 [Success]: ✔ should get next and prev object
 [Success]: ✔ should get many
 [Success]: ✔ should put, get and remove an object in a Obj
 [Success]: ✔ should get  an object in a Obj with default value

    [File]: __tests__/storage.spec.ts
  [Groups]: 3 pass, 3 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 13 pass,  0 fail, 13 total
    [Time]: 407.147ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Describe]: SystemCalls

 [Success]: ✔ should get the chain id
 [Success]: ✔ should get the head info
 [Success]: ✔ should get the transaction
 [Success]: ✔ should get the transaction field
 [Success]: ✔ should get the operation
 [Success]: ✔ should get the block
 [Success]: ✔ should get the block field
 [Success]: ✔ should get the last irreversible block
[Contract Exit] account '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe' authorization failed
[Contract Exit] account '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe' authorization failed
 [Success]: ✔ should require authorities
[Log] Hello World!
 [Success]: ✔ should log
[Event] Hello World! / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe' ] / SGVsbG8gV29ybGQh
[Log] 1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe
 [Success]: ✔ should emit an event
[Contract Exit] unknown hash code
 [Success]: ✔ should hash
[Contract Exit] unexpected dsa
 [Success]: ✔ should recover a public key
 [Success]: ✔ should verify a signature
 [Success]: ✔ should should call a contract
 [Success]: ✔ should get the contract arguments
 [Success]: ✔ should get the contract id
 [Success]: ✔ should get the head info
 [Success]: ✔ should get the caller
[Contract Exit] 
[Contract Exit] my message A
[Contract Exit] my message B
[Contract Exit] my message C
 [Success]: ✔ should exit a contract
 [Success]: ✔ should put and get bytes
 [Success]: ✔ should put and get objects

    [File]: __tests__/systemCalls.spec.ts
  [Groups]: 2 pass, 2 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 22 pass,  0 fail, 22 total
    [Time]: 468.831ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Describe]: token

 [Success]: ✔ should get the name of a token
 [Success]: ✔ should get the symbol of a token
 [Success]: ✔ should get the decimals of a token
 [Success]: ✔ should get the total supply of a token
 [Success]: ✔ should get the balance of an account
 [Success]: ✔ should transfer a token
 [Success]: ✔ should/not mint a token
 [Success]: ✔ should burn a token

    [File]: __tests__/token.spec.ts
  [Groups]: 2 pass, 2 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 8 pass,  0 fail, 8 total
    [Time]: 70.345ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Describe]: Base58

 [Success]: ✔ should decode a Base58 string into a Uint8Array
 [Success]: ✔ should encode a Uint8Array into a Base58 string

[Describe]: Base64

 [Success]: ✔ should decode a Base64 string into a Uint8Array
 [Success]: ✔ should encode a Uint8Array into a Base64 string

[Describe]: StringBytes

 [Success]: ✔ should convert a string into a Uint8Array
 [Success]: ✔ should convert a Uint8Array into a string

[Describe]: Crypto

 [Success]: ✔ should convert a public key into an address
 [Success]: ✔ Multihash class

[Describe]: Arrays

 [Success]: ✔ should compare two Uint8Array
 [Success]: ✔ should convert hex strings

    [File]: __tests__/util.spec.ts
  [Groups]: 6 pass, 6 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 10 pass,  0 fail, 10 total
    [Time]: 168.332ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Coverage Report:

┌──────────────────────────────┬───────┬───────┬───────┬───────┬─────────────────────────────────────────┐
│ File                         │ Total │ Block │ Func  │ Expr  │ Uncovered                               │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/systemCalls.ts      │ 64.3% │ 64.4% │ 63.8% │ 66.7% │ 16:5, 20:9, 25:56, 25:3, 30:46, 30:3... │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/base64.ts      │ 100%  │ 100%  │ 100%  │ 100%  │                                         │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/base58.ts      │ 94.7% │ 91.7% │ 100%  │ 100%  │ 68:40                                   │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/stringBytes.ts │ 100%  │ 100%  │ 100%  │ N/A   │                                         │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/crypto.ts      │ 100%  │ 100%  │ 100%  │ N/A   │                                         │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/arrays.ts      │ 100%  │ 100%  │ 100%  │ 100%  │                                         │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/safeMath.ts    │ 99.2% │ 100%  │ 100%  │ 98.1% │ 262:35                                  │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/mockVM.ts      │ 96.1% │ 96.6% │ 95.5% │ N/A   │ 329:58, 329:3                           │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/token.ts       │ 100%  │ 100%  │ 100%  │ N/A   │                                         │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ assembly/util/storage.ts     │ 100%  │ 100%  │ 100%  │ 100%  │                                         │
├──────────────────────────────┼───────┼───────┼───────┼───────┼─────────────────────────────────────────┤
│ total                        │ 88.4% │ 88%   │ 84.9% │ 94.8% │                                         │
└──────────────────────────────┴───────┴───────┴───────┴───────┴─────────────────────────────────────────┘

  [Summary]
    [Tests]: 180 / 180
   [Groups]: 29 / 29
[Snapshots]: 0 / 0, Added 0, Changed 0
   [Result]: ✔ Pass!
mvandeberg commented 1 year ago

Waiting on merge conflicts to be resolved in https://github.com/koinos/koinos-proto-as/pull/9

mvandeberg commented 1 year ago

Packages just need to bumped to use koinos packages. And I think this should be a minor version bump because it adds support for a newer AS version.

roaminro commented 1 year ago

@mvandeberg I updated the AS version to the latest available (v0.27.1) and updated the build commands. Also, the SDK package version is now v1.1.0