koinos / koinos-sdk-as

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

Bump vm #24

Closed mvandeberg closed 2 years ago

mvandeberg commented 2 years ago

Resolves #21 Resolves #22

Brief description

Updates the SDK to be fully compatible with the new system call changes in testnet-4 and uses up to date MockVM for passing unit tests.

Checklist

Demonstration

yarn test                           
yarn run v1.22.18
$ asp --verbose
       ___   _____                       __    
      /   | / ___/      ____  ___  _____/ /_   
     / /| | \__ \______/ __ \/ _ \/ ___/ __/   
    / ___ |___/ /_____/ /_/ /  __/ /__/ /_     
   /_/  |_/____/     / .___/\___/\___/\__/     
                    /_/                        

⚡AS-pect⚡ Test suite runner [6.2.4]

[Log] Loading asc compiler
Assemblyscript Folder:assemblyscript
[Log] Compiler loaded in 362.633ms.
[Log] Using configuration /Users/mdv/git/koinos-sdk-as/as-pect.config.js
[Log] Using VerboseReporter
[Log] Including files: /Users/mdv/git/koinos-sdk-as/__tests__/**/*.spec.ts
[Log] Running tests that match: (:?)
[Log] Running groups that match: (:?)
[Log] Effective command line args:
  [TestFile.ts] node_modules/@as-pect/assembly/assembly/index.ts --runtime incremental --debug --binaryFile output.wasm --explicitStart --use ASC_RTRACE=1 --exportTable --importMemory --transform /Users/mdv/git/koinos-sdk-as/node_modules/@as-covers/transform/lib/index.js,/Users/mdv/git/koinos-sdk-as/node_modules/@as-pect/core/lib/transform/index.js --lib node_modules/@as-covers/assembly/index.ts

[Describe]: MockVM

 [Success]: ✔ should get the chain id RTrace: +30
 [Success]: ✔ should set the contract arguments RTrace: +51
 [Success]: ✔ should set the contract id RTrace: +27
 [Success]: ✔ should set the head info RTrace: +36
 [Success]: ✔ should set the last irreversible block RTrace: +28
 [Success]: ✔ should set the caller RTrace: +38
 [Success]: ✔ should set the transaction RTrace: +39
 [Success]: ✔ should set the block RTrace: +35
 [Success]: ✔ should set the authorities RTrace: +96
 [Success]: ✔ should set the call contract results RTrace: +76
 [Success]: ✔ should reset the MockVM database RTrace: +71
 [Success]: ✔ should handle transactions RTrace: +191
[Log] log 1
[Log] log 2
[Log] log 3
 [Success]: ✔ should handle logs RTrace: +154
 [Success]: ✔ should handle error messages RTrace: +40

    [File]: /Users/mdv/git/koinos-sdk-as/__tests__/mockVM.spec.ts
  [Groups]: 2 pass, 2 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 14 pass,  0 fail, 14 total
    [Time]: 129.511ms

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

[Describe]: tryAdd

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

[Describe]: add

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

[Describe]: trySub

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

[Describe]: sub

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

[Describe]: tryMul

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

[Describe]: mul

 [Success]: ✔ multiplies correctly RTrace: +16
 [Success]: ✔ multiplies correctly - u128 RTrace: +36
 [Success]: ✔ multiplies by zero correctly RTrace: +16
 [Success]: ✔ multiplies by zero correctly - u128 RTrace: +35
[Contract Exit] could not multiply
[Contract Exit] could not multiply
 [Success]: ✔ reverts on multiplication overflow - u128 RTrace: +884
[Contract Exit] could not multiply 9223372036854775807 by 2
[Contract Exit] could not multiply 2 by 9223372036854775807
 [Success]: ✔ reverts on multiplication overflow RTrace: +98
[Contract Exit] my message
[Contract Exit] my message1
 [Success]: ✔ reverts on multiplication overflow with a custom message RTrace: +92

[Describe]: tryDiv

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

[Describe]: div

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

[Describe]: trymod

[Describe]: modulos correctly

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

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

[Describe]: mod

[Describe]: modulos correctly

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

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

    [File]: /Users/mdv/git/koinos-sdk-as/__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]: 457.183ms

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

[Describe]: space

 [Success]: ✔ should put and get an object RTrace: +48
 [Success]: ✔ should check if space has an object or not RTrace: +41
 [Success]: ✔ should remove an object RTrace: +51
 [Success]: ✔ should get next and prev object RTrace: +131
 [Success]: ✔ should get many RTrace: +688

[Describe]: space with proto key

 [Success]: ✔ should put and get an object RTrace: +44
 [Success]: ✔ should check if space has an object or not RTrace: +41
 [Success]: ✔ should remove an object RTrace: +49
 [Success]: ✔ should get next and prev object RTrace: +131
 [Success]: ✔ should get many RTrace: +483

    [File]: /Users/mdv/git/koinos-sdk-as/__tests__/space.spec.ts
  [Groups]: 3 pass, 3 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 10 pass,  0 fail, 10 total
    [Time]: 174.051ms

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

[Describe]: SystemCalls

 [Success]: ✔ should get the chain id RTrace: +27
 [Success]: ✔ should get the head info RTrace: +36
 [Success]: ✔ should get the transaction RTrace: +39
 [Success]: ✔ should get the transaction field RTrace: +35
 [Success]: ✔ should get the block RTrace: +35
 [Success]: ✔ should get the block field RTrace: +43
 [Success]: ✔ should get the last irreversible block RTrace: +28
[Contract Exit] 
[Contract Exit] 
 [Success]: ✔ should require authorities RTrace: +118
[Log] Hello World!
 [Success]: ✔ should log RTrace: +43
[Event] Hello World! / [ '1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe' ] / SGVsbG8gV29ybGQh
[Log] 1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe
 [Success]: ✔ should emit an event RTrace: +148
[Contract Exit] unknown hash code
 [Success]: ✔ should hash RTrace: +369
[Contract Exit] unexpected dsa
 [Success]: ✔ should recover a public key RTrace: +230
 [Success]: ✔ should verify a signature RTrace: +70
 [Success]: ✔ should should call a contract RTrace: +74
 [Success]: ✔ should get the contract arguments RTrace: +51
 [Success]: ✔ should get the contract id RTrace: +27
 [Success]: ✔ should get the head info RTrace: +36
 [Success]: ✔ should get the caller RTrace: +38
[Contract Result] 
[Contract Exit] 
[Contract Exit] my message
 [Success]: ✔ should exit a contract RTrace: +154
 [Success]: ✔ should put and get bytes RTrace: +313
 [Success]: ✔ should put and get objects RTrace: +202

    [File]: /Users/mdv/git/koinos-sdk-as/__tests__/systemCalls.spec.ts
  [Groups]: 2 pass, 2 total
  [Result]: ✔ PASS
[Snapshot]: 0 total, 0 added, 0 removed, 0 different
 [Summary]: 21 pass,  0 fail, 21 total
    [Time]: 342.47ms

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

[Describe]: token

 [Success]: ✔ should get the name of a token RTrace: +55
 [Success]: ✔ should get the symbol of a token RTrace: +52
 [Success]: ✔ should get the decimals of a token RTrace: +45
 [Success]: ✔ should get the total supply of a token RTrace: +45
 [Success]: ✔ should get the balance of an account RTrace: +45
 [Success]: ✔ should/not tranfer a token RTrace: +88
 [Success]: ✔ should/not mint a token RTrace: +88
 [Success]: ✔ should/not burn a token RTrace: +88

    [File]: /Users/mdv/git/koinos-sdk-as/__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]: 127.92ms

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

[Describe]: Base58

 [Success]: ✔ should decode a Base58 string into a Uint8Array RTrace: +209
 [Success]: ✔ should encode a Uint8Array into a Base58 string RTrace: +113

[Describe]: Base64

 [Success]: ✔ should decode a Base64 string into a Uint8Array RTrace: +69
 [Success]: ✔ should encode a Uint8Array into a Base64 string RTrace: +28

[Describe]: StringBytes

 [Success]: ✔ should convert a string into a Uint8Array RTrace: +22
 [Success]: ✔ should convert a Uint8Array into a string RTrace: +37

[Describe]: Crypto

 [Success]: ✔ should convert a public key into an address RTrace: +161
 [Success]: ✔ Multihash class RTrace: +134

[Describe]: Arrays

 [Success]: ✔ should compare two Uint8Array RTrace: +61
 [Success]: ✔ should convert hex strings RTrace: +188

    [File]: /Users/mdv/git/koinos-sdk-as/__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]: 133.547ms

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

  [Result]: ✔ PASS
   [Files]: 6 total
  [Groups]: 29 count, 29 pass
   [Tests]: 173 pass, 0 fail, 173 total
    [Time]: 46045.305ms
┌──────────────────────────────┬───────┬───────┬───────┬───────┬──────────────────────────────────────────┐
│ File                         │ Total │ Block │ Func  │ Expr  │ Uncovered                                │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ assembly/systemCalls.ts      │ 65.9% │ 66.2% │ 64%   │ 75%   │ 12:7, 41:58, 41:3, 50:76, 50:3, 59:93... │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ assembly/util/base64.ts      │ 100%  │ 100%  │ 100%  │ 100%  │                                          │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ assembly/util/base58.ts      │ 95%   │ 92.3% │ 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    │ 100%  │ 100%  │ 100%  │ 100%  │                                          │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ assembly/util/mockVM.ts      │ 95%   │ 95.7% │ 94.1% │ N/A   │ 267:58, 267:3                            │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ assembly/util/token.ts       │ 100%  │ 100%  │ 100%  │ N/A   │                                          │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ assembly/util/space.ts       │ 100%  │ 100%  │ 100%  │ 100%  │                                          │
├──────────────────────────────┼───────┼───────┼───────┼───────┼──────────────────────────────────────────┤
│ total                        │ 89.6% │ 89.2% │ 85.4% │ 97.5% │                                          │
└──────────────────────────────┴───────┴───────┴───────┴───────┴──────────────────────────────────────────┘

✨  Done in 46.53s.