diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..10e8b2a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,47 @@ +name: Release & Publish + +on: + push: + tags: + - '*' + +permissions: + contents: write + packages: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup .npmrc file to publish to npm + uses: actions/setup-node@v3 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + cache: 'npm' + cache-dependency-path: package-lock.json + - name: Install modules + run: npm install + - name: Build + run: npm run build + - name: Publish to npm + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..87bff0d --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,32 @@ +name: Build & Test + +on: + push: + branches: [main, develop, "feat/*"] + paths-ignore: + - "README.md" + - "LICENSE" + - "example/**" + pull_request: + branches: [main] + paths-ignore: + - "README.md" + - "LICENSE" + - "example/**" + +jobs: + e2e-test: + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }} + uses: actions/setup-node@v4 + with: + node-version: "20.x" + cache: 'npm' + cache-dependency-path: package-lock.json + - name: "Install dependencies" + run: npm install + - name: "Run tests" + run: npm test + diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..c8ac2f5 --- /dev/null +++ b/.npmignore @@ -0,0 +1,23 @@ +.babelrc +.eslintignore +.eslintrc.json +.eslintrc.js +.gitignore +.lintstagedrc.json +.nycrc +.github +.prettierrc.json +.prettierignore +*.log + + +coverage/ +benchmark/ +.coverage/ +cypress/ +fixtures/ +tmp/ +logs/ +test/ +scripts/ +.idea/ diff --git a/contracts/SWTRImplementation.sol b/contracts/SWTRImplementation.sol index b0a9627..9e4113c 100644 --- a/contracts/SWTRImplementation.sol +++ b/contracts/SWTRImplementation.sol @@ -266,8 +266,6 @@ contract SWTRImplementation is ISWTRProxy, OwnableUpgradeable { issuerAddress ); - require(verificationData.length > 0, "No verification data found"); - for (uint256 i = 0; i < verificationData.length; i++) { if ( verificationData[i].verificationType == uint32(verificationType) diff --git a/package-lock.json b/package-lock.json index c7c7910..adce77c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,10 +1,13 @@ { - "name": "swisstronik-sdi-contracts", + "name": "@swisstronik/sdi-contracts", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "swisstronik-sdi-contracts", + "name": "@swisstronik/sdi-contracts", + "version": "1.0.0", + "license": "MIT", "dependencies": { "@nomicfoundation/hardhat-toolbox": "^4.0.0", "@openzeppelin/contracts": "^5.0.2", diff --git a/package.json b/package.json index 4d146cb..1ca9b5d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,20 @@ { - "name": "swisstronik-sdi-contracts", + "name": "@swisstronik/sdi-contracts", + "version": "1.0.0", + "description": "Swisstronik SDI contracts", + "homepage": "https://github.com/SigmaGmbH/swisstronik-sdi-contracts", + "bugs": { + "url": "https://github.com/SigmaGmbH/swisstronik-sdi-contracts/issues" + }, + "contributors": [ + "Denis ", + "Lesther Caballero " + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/SigmaGmbH/swisstronik-sdi-contracts.git" + }, "dependencies": { "@nomicfoundation/hardhat-toolbox": "^4.0.0", "@openzeppelin/contracts": "^5.0.2", @@ -13,6 +28,7 @@ }, "scripts": { "hardhat:compile": "hardhat compile --force", - "hardhat:deploy": "hardhat run scripts/deploy.ts --network testnet" + "hardhat:deploy": "hardhat run scripts/deploy.ts --network testnet", + "test": "hardhat test" } } diff --git a/test/Lock.ts b/test/Lock.ts deleted file mode 100644 index a6e866b..0000000 --- a/test/Lock.ts +++ /dev/null @@ -1,127 +0,0 @@ -import { - time, - loadFixture, -} from "@nomicfoundation/hardhat-toolbox/network-helpers"; -import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs"; -import { expect } from "chai"; -import { ethers } from "hardhat"; - -describe("Lock", function () { - // We define a fixture to reuse the same setup in every test. - // We use loadFixture to run this setup once, snapshot that state, - // and reset Hardhat Network to that snapshot in every test. - async function deployOneYearLockFixture() { - const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60; - const ONE_GWEI = 1_000_000_000; - - const lockedAmount = ONE_GWEI; - const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS; - - // Contracts are deployed using the first signer/account by default - const [owner, otherAccount] = await ethers.getSigners(); - - const Lock = await ethers.getContractFactory("Lock"); - const lock = await Lock.deploy(unlockTime, { value: lockedAmount }); - - return { lock, unlockTime, lockedAmount, owner, otherAccount }; - } - - describe("Deployment", function () { - it("Should set the right unlockTime", async function () { - const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture); - - expect(await lock.unlockTime()).to.equal(unlockTime); - }); - - it("Should set the right owner", async function () { - const { lock, owner } = await loadFixture(deployOneYearLockFixture); - - expect(await lock.owner()).to.equal(owner.address); - }); - - it("Should receive and store the funds to lock", async function () { - const { lock, lockedAmount } = await loadFixture( - deployOneYearLockFixture - ); - - expect(await ethers.provider.getBalance(lock.target)).to.equal( - lockedAmount - ); - }); - - it("Should fail if the unlockTime is not in the future", async function () { - // We don't use the fixture here because we want a different deployment - const latestTime = await time.latest(); - const Lock = await ethers.getContractFactory("Lock"); - await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith( - "Unlock time should be in the future" - ); - }); - }); - - describe("Withdrawals", function () { - describe("Validations", function () { - it("Should revert with the right error if called too soon", async function () { - const { lock } = await loadFixture(deployOneYearLockFixture); - - await expect(lock.withdraw()).to.be.revertedWith( - "You can't withdraw yet" - ); - }); - - it("Should revert with the right error if called from another account", async function () { - const { lock, unlockTime, otherAccount } = await loadFixture( - deployOneYearLockFixture - ); - - // We can increase the time in Hardhat Network - await time.increaseTo(unlockTime); - - // We use lock.connect() to send a transaction from another account - await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith( - "You aren't the owner" - ); - }); - - it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () { - const { lock, unlockTime } = await loadFixture( - deployOneYearLockFixture - ); - - // Transactions are sent using the first signer by default - await time.increaseTo(unlockTime); - - await expect(lock.withdraw()).not.to.be.reverted; - }); - }); - - describe("Events", function () { - it("Should emit an event on withdrawals", async function () { - const { lock, unlockTime, lockedAmount } = await loadFixture( - deployOneYearLockFixture - ); - - await time.increaseTo(unlockTime); - - await expect(lock.withdraw()) - .to.emit(lock, "Withdrawal") - .withArgs(lockedAmount, anyValue); // We accept any value as `when` arg - }); - }); - - describe("Transfers", function () { - it("Should transfer the funds to the owner", async function () { - const { lock, unlockTime, lockedAmount, owner } = await loadFixture( - deployOneYearLockFixture - ); - - await time.increaseTo(unlockTime); - - await expect(lock.withdraw()).to.changeEtherBalances( - [owner, lock], - [lockedAmount, -lockedAmount] - ); - }); - }); - }); -});