-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Serialization of contract artifact
- Loading branch information
1 parent
4aca2f5
commit 4f2563f
Showing
7 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
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,7 @@ | ||
{ | ||
"scripts": { | ||
"build": "yarn clean && yarn generate && tsc -b", | ||
"generate": "yarn generate:noir-contracts", | ||
"generate:noir-contracts": "./scripts/copy-contracts.sh" | ||
} | ||
} |
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 @@ | ||
#! /bin/bash | ||
set -euo pipefail | ||
mkdir -p ./fixtures | ||
|
||
cp "../../noir-projects/noir-contracts/target/benchmarking_contract-Benchmarking.json" ./fixtures/Benchmarking.test.json |
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,12 @@ | ||
import { getSampleContractArtifact } from '../test/fixtures.js'; | ||
import { contractArtifactFromBuffer, contractArtifactToBuffer } from './contract_artifact.js'; | ||
|
||
describe('contract_artifact', () => { | ||
it('serializes and deserializes an instance', () => { | ||
const artifact = getSampleContractArtifact(); | ||
delete artifact.aztecNrVersion; | ||
const serialized = contractArtifactToBuffer(artifact); | ||
const deserialized = contractArtifactFromBuffer(serialized); | ||
expect(deserialized).toEqual(artifact); | ||
}); | ||
}); |
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,19 @@ | ||
import { ContractArtifact } from '@aztec/foundation/abi'; | ||
|
||
import { readFileSync } from 'fs'; | ||
import { dirname, resolve } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import { loadContractArtifact } from '../abi/contract_artifact.js'; | ||
import { NoirCompiledContract } from '../noir/index.js'; | ||
|
||
// Copied from the build output for the contract `Benchmarking` in noir-contracts | ||
export function getSampleContractArtifact(): ContractArtifact { | ||
const path = getPathToFixture('Benchmarking.test.json'); | ||
const content = JSON.parse(readFileSync(path).toString()) as NoirCompiledContract; | ||
return loadContractArtifact(content); | ||
} | ||
|
||
function getPathToFixture(name: string) { | ||
return resolve(dirname(fileURLToPath(import.meta.url)), `../../fixtures/${name}`); | ||
} |