Skip to content

Commit

Permalink
Fix CR
Browse files Browse the repository at this point in the history
  • Loading branch information
gregLibert committed May 2, 2024
1 parent c518b6c commit 63c039c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/massa-web3/src/experimental/basicElements/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Base58 from '../crypto/base58'
import Serializer from '../crypto/interfaces/serializer'
import { Version, Versioner } from '../crypto/interfaces/versioner'
import VarintVersioner from '../crypto/varintVersioner'
import { FIRST } from '../utils'
import { PublicKey } from './keys'
import varint from 'varint'

Expand Down Expand Up @@ -230,8 +231,7 @@ export class Address {
*/
static extractFromBuffer(
data: Uint8Array,
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
offset = 0
offset = FIRST
): { data: Uint8Array; length: number } {
// addr type
varint.decode(data, offset)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Serializer from '../crypto/interfaces/serializer'
import { Versioner, Version } from '../crypto/interfaces/versioner'
import { FIRST, ONE } from '../utils'

/**
* Deserialize a string data into non versioned bytes and checks that expected version match.
Expand Down Expand Up @@ -31,12 +32,10 @@ export function extractData(
* @returns the extracted prefix.
*/
export function mustExtractPrefix(str: string, ...expected: string[]): string {
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const prefix = str.slice(0, expected[0].length)
const prefix = str.slice(FIRST, expected[FIRST].length)
if (!expected.includes(prefix)) {
throw new Error(
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
`invalid prefix: ${prefix}. ${expected.length > 1 ? 'one of ' : ''}${expected.join(' or ')} was expected.`
`invalid prefix: ${prefix}. ${expected.length > ONE ? 'one of ' : ''}${expected.join(' or ')} was expected.`
)
}
return prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PrivateKey, PublicKey } from './keys'
import { BlockchainClient } from '../client'
import { Signature } from './signature'
import varint from 'varint'
import { FIRST } from '../utils'

// TODO: replace with a U64 helper
const U64_SIZE_BYTES = 8
Expand Down Expand Up @@ -31,7 +32,7 @@ export enum OperationType {
*
* @remarks
* Period to live is the number of periods the operation is valid for.
* This value must be positive and if it's too big, the node will (sliently?) reject the operation.
* This value must be positive and if it's too big, the node will (silently?) reject the operation.
*
* If no fee is provided, minimal fee of connected node is used.
* If no periodToLive is provided, the DefaultPeriodToLive is used.
Expand Down Expand Up @@ -117,6 +118,17 @@ export class OperationManager {
operation = operation as RollOperation
components.push(unsigned.encode(operation.amount))
break
case OperationType.CallSmartContractFunction:
// @see https://docs.massa.net/docs/learn/operation-format-execution#callsc-operation-payload
operation = operation as CallOperation

Check warning on line 123 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(unsigned.encode(operation.maxGas))

Check warning on line 124 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(unsigned.encode(operation.coins))

Check warning on line 125 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(Address.fromString(operation.address).toBytes())

Check warning on line 126 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(varint.encode(operation.func.length))

Check warning on line 127 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(Buffer.from(operation.func))

Check warning on line 128 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(varint.encode(operation.parameter.length))

Check warning on line 129 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
components.push(operation.parameter)

Check warning on line 130 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
break

Check warning on line 131 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 131 in packages/massa-web3/src/experimental/basicElements/operationManager.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
case OperationType.ExecuteSmartContractBytecode:
operation = operation as ExecuteOperation
components.push(unsigned.encode(operation.maxGas))
Expand Down Expand Up @@ -156,8 +168,7 @@ export class OperationManager {
* @returns An new instance of OperationDetails representing the deserialized operation.
*/
static deserialize(data: Uint8Array): OperationDetails {
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
let offset = 0
let offset = FIRST
const nextVarInt = (): bigint => {
const value = unsigned.decode(data, offset)
offset += unsigned.encodingLength(value)
Expand Down Expand Up @@ -213,8 +224,7 @@ export class OperationManager {
// u64ToBytes is little endian
const networkId = new Uint8Array(U64_SIZE_BYTES)
const view = new DataView(networkId.buffer)
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
view.setBigUint64(0, chainId, false)
view.setBigUint64(FIRST, chainId, false)

const data = OperationManager.serialize(operation)
const publicKeyBytes = key.toBytes()
Expand Down
1 change: 1 addition & 0 deletions packages/massa-web3/src/experimental/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './numbers'
export * from './noMagic'
2 changes: 2 additions & 0 deletions packages/massa-web3/src/experimental/utils/noMagic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const FIRST = 0
export const ONE = 1

0 comments on commit 63c039c

Please sign in to comment.