-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into chore/add-datamapper-examples
- Loading branch information
Showing
8 changed files
with
2,179 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import VeraxSdk from "../../src/VeraxSdk"; | ||
|
||
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET); | ||
|
||
// This example relies on a complex Schema written by Clique | ||
console.log( | ||
JSON.stringify( | ||
veraxSdk.utils.decode( | ||
"((string type, ((string name, uint256 count)[] GameGenres, (string name, uint256 count)[] GameSetting, (string name, uint256 count)[] PlayStyle) items, (string type, (string level, string hoursPlayedSteam) items) subHoursPlayedSteam, (string type, (string topTag, string hoursSteam) items) gameGenresTopTagByHoursSteam, (string type, (string playstyle, string hoursSteam) items) playstyleTopTagByHoursSteam, string sumHourByTop10GamesSteam) userGamingPieChartSteam)", | ||
"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000006200000000000000000000000000000000000000000000000000000000000000760000000000000000000000000000000000000000000000000000000000000000352504700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000000967616d6567656e72650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007c000000000000000000000000000000000000000000000000000000000000000873657474696e6731000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000007d0000000000000000000000000000000000000000000000000000000000000009706c61795374796c65000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001774797065537562486f757273506c61796564537465616d0000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000053e39393939000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000331323500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000207479706567616d6547656e726573546f705461674279486f757273537465616d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000006746f7054616700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004313236380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001f74797065706c61797374796c65546f705461674279486f757273537465616d00000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000009706c61797374796c6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006313235383734000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093132353839363534310000000000000000000000000000000000000000000000", | ||
), | ||
(key, value) => (typeof value === "bigint" ? value.toString() : value), // return everything else unchanged | ||
2, | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import VeraxSdk from "../../src/VeraxSdk"; | ||
|
||
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET); | ||
|
||
// This example relies on a complex Schema written by Clique | ||
console.log( | ||
veraxSdk.utils.encode( | ||
"((string type, ((string name, uint256 count)[] GameGenres, (string name, uint256 count)[] GameSetting, (string name, uint256 count)[] PlayStyle) items, (string type, (string level, string hoursPlayedSteam) items) subHoursPlayedSteam, (string type, (string topTag, string hoursSteam) items) gameGenresTopTagByHoursSteam, (string type, (string playstyle, string hoursSteam) items) playstyleTopTagByHoursSteam, string sumHourByTop10GamesSteam) userGamingPieChartSteam)", | ||
[ | ||
{ | ||
userGamingPieChartSteam: { | ||
type: "RPG", | ||
items: { | ||
GameGenres: [ | ||
{ | ||
name: "gamegenre", | ||
count: 123, | ||
}, | ||
], | ||
GameSetting: [ | ||
{ | ||
name: "setting1", | ||
count: 124, | ||
}, | ||
], | ||
PlayStyle: [ | ||
{ | ||
name: "playStyle", | ||
count: 125, | ||
}, | ||
], | ||
}, | ||
subHoursPlayedSteam: { | ||
type: "typeSubHoursPlayedSteam", | ||
items: { | ||
level: ">9999", | ||
hoursPlayedSteam: "125", | ||
}, | ||
}, | ||
gameGenresTopTagByHoursSteam: { | ||
type: "typegameGenresTopTagByHoursSteam", | ||
items: { | ||
topTag: "topTag", | ||
hoursSteam: "1268", | ||
}, | ||
}, | ||
playstyleTopTagByHoursSteam: { | ||
type: "typeplaystyleTopTagByHoursSteam", | ||
items: { | ||
playstyle: "playstyle", | ||
hoursSteam: "125874", | ||
}, | ||
}, | ||
sumHourByTop10GamesSteam: "125896541", | ||
}, | ||
}, | ||
], | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
// ... other Jest configuration options | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { decodeAbiParameters, encodeAbiParameters, parseAbiParameters } from "viem"; | ||
|
||
export function encode(schema: string, values: unknown[]): `0x${string}` { | ||
return encodeAbiParameters(parseAbiParameters(schema), values); | ||
} | ||
|
||
export function decode(schema: string, attestationData: `0x${string}`): readonly unknown[] { | ||
return decodeAbiParameters(parseAbiParameters(schema), attestationData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import AttestationDataMapper from "../../src/dataMapper/AttestationDataMapper"; | ||
import VeraxSdk from "../../src/VeraxSdk"; | ||
import { createPublicClient, PublicClient, http } from "viem"; | ||
import { ApolloClient, InMemoryCache, ApolloQueryResult, gql } from "@apollo/client/core"; | ||
//TODO : This is a basic test example. mock data and assertions should be more precise | ||
describe("AttestationDataMapper", () => { | ||
let mockApolloClient: ApolloClient<object>; | ||
let web3Client: PublicClient; | ||
let attestationDataMapper: AttestationDataMapper; | ||
const typeName: string = "attestation"; | ||
const gqlInterface: string = `{ | ||
id | ||
schemaId | ||
replacedBy | ||
attester | ||
portal | ||
attestedDate | ||
expirationDate | ||
revocationDate | ||
version | ||
revoked | ||
subject | ||
attestationData | ||
schemaString | ||
decodedData | ||
}`; | ||
|
||
beforeAll(() => { | ||
// Create web3Client | ||
web3Client = createPublicClient({ | ||
chain: VeraxSdk.DEFAULT_LINEA_TESTNET.chain, | ||
transport: http(), | ||
}); | ||
|
||
// Create a mock Apollo Client with an in-memory cache | ||
mockApolloClient = new ApolloClient({ | ||
cache: new InMemoryCache(), | ||
}); | ||
|
||
attestationDataMapper = new AttestationDataMapper(VeraxSdk.DEFAULT_LINEA_TESTNET, web3Client, mockApolloClient); | ||
}); | ||
|
||
afterEach(() => { | ||
// Clear the mock function's call history after each test | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("findOneById", () => { | ||
it("should return the expected attestation", async () => { | ||
const attestationId = "attestationId1"; | ||
// Mock the behavior of the query method | ||
const queryMock = jest.spyOn(mockApolloClient, "query"); | ||
queryMock.mockResolvedValueOnce({ | ||
data: { | ||
attestation: { result: "success" }, | ||
}, | ||
} as ApolloQueryResult<unknown>); | ||
|
||
const result = await attestationDataMapper.findOneById(attestationId); | ||
|
||
// Assert | ||
expect(result).toBe('{"result":"success"}'); | ||
expect(mockApolloClient.query).toHaveBeenCalledWith({ | ||
query: gql(`query GetOne($id: ID!) { ${typeName}(id: $id) ${gqlInterface} }`), | ||
variables: { id: attestationId }, | ||
}); | ||
}); | ||
}); | ||
}); |