Skip to content

Commit

Permalink
fix: en_7 recommendations... (#1749)
Browse files Browse the repository at this point in the history
* fix: fr9 recommendations

* fix: en_1 recommendations

* fix: en_1 recommendations

* fix: en_2 recommendations...

* fix: en_2 recommendations...

* fix: en_7 recommendations...

* fix: en_7 recommendations...

* fix: n_7 recommandations

* fix: n_7 recommandations

* Merge branch 'main' into 1656-fr9

* Merge branch '1661-en_2' into 1662-en_7

* fix: EN_7

* fix: EN_7

* fix: EN_7

---------

Co-authored-by: Fabio Rigamonti <[email protected]>

(cherry picked from commit f52a556)
  • Loading branch information
lucanicoladebiasi committed Feb 5, 2025
1 parent f5020f3 commit 7d907dc
Show file tree
Hide file tree
Showing 24 changed files with 123 additions and 82 deletions.
8 changes: 4 additions & 4 deletions apps/sdk-cloudflare-integration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"strict": true,
"module": "esnext",
"target": "esnext",
"module": "Node16",
"target": "ES2023",
"lib": [
"esnext"
],
"moduleResolution": "bundler",
"moduleResolution": "Node16",
"noEmit": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
Expand All @@ -18,4 +18,4 @@
"./**/*.ts"
]
}
}
}
6 changes: 3 additions & 3 deletions apps/sdk-nextjs-integration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"module": "Node16",
"moduleResolution": "Node16",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand All @@ -30,7 +30,7 @@
"**/*.ts",
"**/*.tsx",
"types.d.ts",
".next/types/**/*.ts",
".next/types/**/*.ts",
"jest.config.js" ],
"exclude": ["node_modules"]
}
6 changes: 3 additions & 3 deletions apps/sdk-vite-integration/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { BrowserRouter as Router, Route, Routes, Link } from 'react-router-dom';
import reactLogo from './assets/react.svg';
import viteLogo from '/vite.svg';
import './App.css';
import Hash from './components/Hash';
import TransferLogs from './components/TransferLogs';
import GetLastBlock from './components/GetLastBlock';
import Hash from './components/Hash.tsx';
import TransferLogs from './components/TransferLogs.tsx';
import GetLastBlock from './components/GetLastBlock.tsx';

function App() {
return (
Expand Down
13 changes: 4 additions & 9 deletions apps/sdk-vite-integration/src/components/GetLastBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { type CompressedBlockDetail, ThorClient } from "@vechain/sdk-network";
import { type CompressedBlockDetail } from "@vechain/sdk-network";
import { useState } from "react";
import { thorClient } from '../const/index.tsx';

const GetLastBlock = () => {
const [block, setBlock] = useState<CompressedBlockDetail | null>(null);

// URL of the VeChain mainnet
const mainnetUrl = 'https://mainnet.vechain.org';

// Thor client instance
const thorClient = ThorClient.fromUrl(mainnetUrl);

// Function to fetch the last block
const fetchLastBlock = async () => {
try {
Expand All @@ -22,13 +17,13 @@ const GetLastBlock = () => {

return (
<div>
<button onClick={fetchLastBlock}>
<button onClick={fetchLastBlock} data-testid="getlastblock">
Get Last Block
</button>
{block && (
<div>
<h3>Last Block Details:</h3>
<pre>{JSON.stringify(block, null, 2)}</pre>
<pre data-testid="last-block-details">{JSON.stringify(block, null, 2)}</pre>
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/sdk-vite-integration/src/components/Hash.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Blake2b256, Keccak256, Sha256, Txt } from '@vechain/sdk-core';
import { useEffect, useState } from 'react';
import { HashedContent } from '../types';
import { HashedContent } from '../types/index.tsx';

const Hash = () => {
// State of content to hash
Expand Down
4 changes: 2 additions & 2 deletions apps/sdk-vite-integration/src/components/TransferLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
FilterTransferLogsOptions
} from '@vechain/sdk-network';
import { Link } from 'react-router-dom';
import { Transfer } from "../types";
import { explorerUrl, thorClient } from "../const";
import { Transfer } from "../types/index.tsx";
import { explorerUrl, thorClient } from "../const/index.tsx";

/**
* Reduce the size of a hex string
Expand Down
2 changes: 1 addition & 1 deletion apps/sdk-vite-integration/src/const/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line react-refresh/only-export-components
export * from './const';
export * from '../const/const.tsx';
2 changes: 1 addition & 1 deletion apps/sdk-vite-integration/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
<StrictMode>
Expand Down
2 changes: 1 addition & 1 deletion apps/sdk-vite-integration/src/types/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type * from './types.d';
export type * from './types.d.tsx';
4 changes: 2 additions & 2 deletions apps/sdk-vite-integration/tests/Hash.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test } from 'vitest'
import { render } from 'vitest-browser-react'
import Hash from '../src/components/Hash'
import Hash from '../src/components/Hash.js'

test('renders name', async () => {
const { getByText } = render(<Hash />)

await expect.element(getByText('0xbf56c0728fd4e9cf64bfaf6dabab81554103298cdee5cc4d580433aa25e98b00')).toBeInTheDocument()
})
})
4 changes: 2 additions & 2 deletions apps/sdk-vite-integration/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"module": "Node16",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"moduleResolution": "Node16",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
Expand Down
21 changes: 11 additions & 10 deletions apps/sdk-vite-integration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["esnext", "dom"],
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"types": ["@vitest/browser/providers/playwright"],
"strict": true,
"allowImportingTsExtensions": true,
"declaration": true,
"noEmit": true,
"esModuleInterop": true,
"skipLibCheck": true
"jsx": "react-jsx",
"lib": ["esnext", "dom"],
"module": "Node16",
"moduleResolution": "Node16",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2023",
"types": ["@vitest/browser/providers/playwright"]
}
}
}
4 changes: 2 additions & 2 deletions apps/sdk-vite-integration/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"module": "Node16",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"moduleResolution": "Node16",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
Expand Down
14 changes: 7 additions & 7 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2023",
"module": "Node16",
"moduleResolution": "Node16",
"allowSyntheticDefaultImports": true,
},
"ts-node": {
"compilerOptions": {
"esModuleInterop": true,
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Node",
"module": "Node16",
"target": "ES2023",
"moduleResolution": "Node16",
},
"esm": true
}
}
}
17 changes: 16 additions & 1 deletion packages/aws-kms-adapter/tests/KMSVeChainSigner.solo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,22 @@ describe('KMSVeChainSigner - Thor Solo', () => {
);
expect(signature).toBeDefined();
// 64-bytes hex string
expect(signature.length).toBe(132);
expect(signature).toMatch(/^0x[A-Fa-f0-9]{130}$/);

const signatureWithoutPrimaryType = await signer.signTypedData(
typedData.domain,
typedData.types,
typedData.data
);
expect(signatureWithoutPrimaryType).toBeDefined();
// 64-bytes hex string
expect(signatureWithoutPrimaryType).toMatch(/^0x[A-Fa-f0-9]{130}$/);

// Not checking directly the signatures since there is an issue in LocalStack:
// https://github.com/localstack/localstack/issues/11678
// Looks like, regardless the configuration, a new SECP256r1 key is generated
// meaning that the signature will be different every time.
// However both hashes have been checked and they match, + tests in the other implementation.
});
});
});
3 changes: 1 addition & 2 deletions packages/network/src/thor-client/blocks/blocks-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BlocksModule {

/**
* Initializes a new instance of the `Thor` class.
* @param thor - The Thor instance used to interact with the VeChain blockchain API.
* @param httpClient - The Thor instance used to interact with the VeChain blockchain API.
* @param options - (Optional) Other optional parameters for polling and error handling.
*/
constructor(
Expand Down Expand Up @@ -306,7 +306,6 @@ class BlocksModule {
addresses.add(clause.to);
}
});
addresses.add(transaction.delegator);
addresses.add(transaction.gasPayer);
addresses.add(transaction.origin);
transaction.outputs.forEach((output) => {
Expand Down
5 changes: 0 additions & 5 deletions packages/network/src/thor-client/blocks/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ interface TransactionsExpandedBlockDetail {
*/
origin: string;

/**
* Delegator associated with the transaction.
*/
delegator: string;

/**
* Nonce value for preventing replay attacks.
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/network/tests/provider/formatter/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const blockFixtures = [
gasPriceCoef: 64,
gas: 29750,
origin: '0x7487d912d03ab9de786278f679592b3730bdd540',
delegator: 'null',
nonce: '0xb8314776ce0bf5df',
dependsOn: 'null',
size: 191,
Expand Down Expand Up @@ -208,7 +207,6 @@ const blockFixtures = [
gasPriceCoef: 64,
gas: 48432,
origin: '0x7487d912d03ab9de786278f679592b3730bdd540',
delegator: 'null',
nonce: '0x176bbcbf79a3a672',
dependsOn: 'null',
size: 219,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
test
} from '@jest/globals';
import { Address, Hex, HexUInt, Secp256k1, Txt } from '@vechain/sdk-core';
import { Wallet } from 'ethers';
import { type TypedDataDomain, Wallet } from 'ethers';
import {
TESTNET_URL,
ThorClient,
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('VeChain base signer tests', () => {

await expect(
signer.signMessage(EIP191_MESSAGE)
).rejects.toThrowError('Error while signing the message');
).rejects.toThrowError();
});

test('signMessage - ethers compatible - string', async () => {
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('VeChain base signer tests', () => {
eip712TestCases.invalid.types,
eip712TestCases.invalid.data
)
).rejects.toThrowError(TypeError);
).rejects.toThrowError();
});

test('signTypedData - exception when parsing to hex', async () => {
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('VeChain base signer tests', () => {
eip712TestCases.valid.types,
eip712TestCases.valid.data
)
).rejects.toThrowError('Error while signing typed data');
).rejects.toThrowError();
});

test('signTypedData - ethers compatible', async () => {
Expand All @@ -335,15 +335,57 @@ describe('VeChain base signer tests', () => {
eip712TestCases.valid.data
);
expect(expected).toBe(eip712TestCases.valid.signature);
const actual = await new VeChainPrivateKeySigner(
const privateKeySigner = new VeChainPrivateKeySigner(
Hex.of(eip712TestCases.valid.privateKey).bytes,
provider
).signTypedData(
);
const actual = await privateKeySigner.signTypedData(
eip712TestCases.valid.domain,
eip712TestCases.valid.types,
eip712TestCases.valid.data
);
expect(actual).toBe(expected);
const actualWithoutPrimaryType =
await privateKeySigner.signTypedData(
eip712TestCases.valid.domain,
eip712TestCases.valid.types,
eip712TestCases.valid.data
);
expect(actualWithoutPrimaryType).toBe(expected);

// Using VeChain chainId as string and bigint
const vechainChainId =
'1176455790972829965191905223412607679856028701100105089447013101863';
const expectedVeChain = await new Wallet(
eip712TestCases.valid.privateKey
).signTypedData(
{
...eip712TestCases.valid.domain,
chainId: vechainChainId
},
eip712TestCases.valid.types,
eip712TestCases.valid.data
);
const actualWithStringChainId =
await privateKeySigner.signTypedData(
{
...eip712TestCases.valid.domain,
chainId: vechainChainId
},
eip712TestCases.valid.types,
eip712TestCases.valid.data
);
expect(actualWithStringChainId).toBe(expectedVeChain);
const actualWithBigintChainId =
await privateKeySigner.signTypedData(
{
...(eip712TestCases.valid.domain as TypedDataDomain),
chainId: BigInt(vechainChainId)
},
eip712TestCases.valid.types,
eip712TestCases.valid.data
);
expect(actualWithBigintChainId).toBe(expectedVeChain);
});
});
});
Loading

1 comment on commit 7d907dc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 98%
98.91% (4371/4419) 97.2% (1392/1432) 98.8% (906/917)
Title Tests Skipped Failures Errors Time
core 838 0 πŸ’€ 0 ❌ 0 πŸ”₯ 2m 30s ⏱️
network 731 0 πŸ’€ 0 ❌ 0 πŸ”₯ 5m 12s ⏱️
errors 40 0 πŸ’€ 0 ❌ 0 πŸ”₯ 18.468s ⏱️
logging 3 0 πŸ’€ 0 ❌ 0 πŸ”₯ 19.234s ⏱️
hardhat-plugin 19 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 9s ⏱️
aws-kms-adapter 23 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 31s ⏱️
ethers-adapter 5 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 20s ⏱️
rpc-proxy 37 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 26s ⏱️

Please sign in to comment.