Skip to content

Commit

Permalink
feat(contracts): AG-52 removed getters
Browse files Browse the repository at this point in the history
removed getters from the DEC smart contract
  • Loading branch information
g3k0 committed Apr 22, 2024
1 parent 6af9a66 commit 3f42425
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 55 deletions.
26 changes: 4 additions & 22 deletions contracts/DEC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pragma solidity ^0.8.24;
/// @custom:experimental This is an experimental contract.
contract DEC {
address public owner;
Encrypted taxCode;
Encrypted municipality;
Encrypted region;
Encrypted country;
Encrypted public taxCode;
Encrypted public municipality;
Encrypted public region;
Encrypted public country;

struct Encrypted {
string sha;
Expand Down Expand Up @@ -40,33 +40,15 @@ contract DEC {
taxCode = _taxCode;
}

function getTaxCode() external view returns (Encrypted memory) {
return taxCode;
}

function setMunicipality(Encrypted memory _municipality) external onlyOwner {
municipality = _municipality;
}

function getMunicipality() external view returns (Encrypted memory) {
return municipality;
}

function setRegion(Encrypted memory _region) external onlyOwner {
region = _region;
}

function getRegion() external view returns (Encrypted memory) {
return region;
}

function setCountry(Encrypted memory _country) external onlyOwner {
country = _country;
}

function getCountry() external view returns (Encrypted memory) {
return country;
}


}
66 changes: 33 additions & 33 deletions test/DEC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe("DEC Contract", () => {
let dec: DEC;

const encryptedDataFactory = function (
sha: string,
chiper: string,
nonce: string,
sha: string,
): Encrypted {
return {
chiper,
Expand Down Expand Up @@ -47,33 +47,33 @@ describe("DEC Contract", () => {
await (await ethers.provider.getSigner(0)).getAddress(),
);

const registeredTaxCode = await dec.getTaxCode();
const registeredMunicipality = await dec.getMunicipality();
const registeredRegion = await dec.getRegion();
const registeredCountry = await dec.getCountry();
const registeredTaxCode: Encrypted = await dec.taxCode();
const registeredMunicipality: Encrypted = await dec.municipality();
const registeredRegion: Encrypted = await dec.region();
const registeredCountry: Encrypted = await dec.country();

const enTaxCode = encryptedDataFactory(
registeredTaxCode[0],
registeredTaxCode[1],
registeredTaxCode[2],
registeredTaxCode.chiper,
registeredTaxCode.nonce,
registeredTaxCode.sha,
);

const enMunicipality = encryptedDataFactory(
registeredMunicipality[0],
registeredMunicipality[1],
registeredMunicipality[2],
registeredMunicipality.chiper,
registeredMunicipality.nonce,
registeredMunicipality.sha,
);

const enRegion = encryptedDataFactory(
registeredRegion[0],
registeredRegion[1],
registeredRegion[2],
registeredRegion.chiper,
registeredRegion.nonce,
registeredRegion.sha,
);

const enCountry = encryptedDataFactory(
registeredCountry[0],
registeredCountry[1],
registeredCountry[2],
registeredCountry.chiper,
registeredCountry.nonce,
registeredCountry.sha,
);

const decodedTaxCode = decryptString(
Expand Down Expand Up @@ -106,12 +106,12 @@ describe("DEC Contract", () => {
it("Should set and get tax code correctly", async () => {
await dec.setTaxCode(eTaxCode);

const getTaxCode = await dec.getTaxCode();
const getTaxCode = await dec.taxCode();

const gTaxCode = encryptedDataFactory(
getTaxCode[0],
getTaxCode[1],
getTaxCode[2],
getTaxCode.chiper,
getTaxCode.nonce,
getTaxCode.sha,
);

assert.equal(JSON.stringify(eTaxCode), JSON.stringify(gTaxCode));
Expand All @@ -120,12 +120,12 @@ describe("DEC Contract", () => {
it("Should set and get municipality correctly", async () => {
await dec.setMunicipality(eMunicipality);

const getMunicipality = await dec.getMunicipality();
const getMunicipality = await dec.municipality();

const gMunicipality = encryptedDataFactory(
getMunicipality[0],
getMunicipality[1],
getMunicipality[2],
getMunicipality.chiper,
getMunicipality.nonce,
getMunicipality.sha,
);

assert.equal(JSON.stringify(eMunicipality), JSON.stringify(gMunicipality));
Expand All @@ -134,12 +134,12 @@ describe("DEC Contract", () => {
it("Should set and get region correctly", async () => {
await dec.setRegion(eRegion);

const getRegion = await dec.getRegion();
const getRegion = await dec.region();

const gRegion = encryptedDataFactory(
getRegion[0],
getRegion[1],
getRegion[2],
getRegion.chiper,
getRegion.nonce,
getRegion.sha,
);

assert.equal(JSON.stringify(eRegion), JSON.stringify(gRegion));
Expand All @@ -148,12 +148,12 @@ describe("DEC Contract", () => {
it("Should set and get country correctly", async () => {
await dec.setCountry(eCountry);

const getCountry = await dec.getCountry();
const getCountry = await dec.country();

const gCountry = encryptedDataFactory(
getCountry[0],
getCountry[1],
getCountry[2],
getCountry.chiper,
getCountry.nonce,
getCountry.sha,
);

assert.equal(JSON.stringify(eCountry), JSON.stringify(gCountry));
Expand Down

0 comments on commit 3f42425

Please sign in to comment.