Skip to content

Commit

Permalink
Merge pull request #632 from nevermined-io/feat/small_improvements
Browse files Browse the repository at this point in the history
Export SDK in the NvmApp API and tests
  • Loading branch information
aaitor authored Feb 19, 2024
2 parents 8de5077 + 0b9aa70 commit 952dc8e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
38 changes: 37 additions & 1 deletion integration/nevermined/NFT1155.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import chai, { assert } from 'chai'
import { decodeJwt, JWTPayload } from 'jose'
import chaiAsPromised from 'chai-as-promised'
import { Account, DDO, Nevermined, AssetPrice, NFTAttributes, ContractHandler } from '../../src'
import {
Account,
DDO,
Nevermined,
AssetPrice,
NFTAttributes,
ContractHandler,
ChargeType,
NFTServiceAttributes,
} from '../../src'
import { config } from '../config'
import { getMetadata } from '../utils'
import { getRoyaltyAttributes, RoyaltyKind } from '../../src/nevermined'
Expand Down Expand Up @@ -93,6 +102,33 @@ describe('NFT1155 End-to-End', () => {
})
})

describe('As publisher I can setup different charging mechanisms', () => {
it('Should be able to charge fixed amounts', async () => {
const chargeType = ChargeType.Fixed
const nftService = new NFTServiceAttributes()
nftService.amount = 2n

const amountToCharge = NFTServiceAttributes.getCreditsToCharge(nftService, chargeType)
assert.equal(amountToCharge, 2n)
})

it('Should be able to charge dynamic amounts', async () => {
const chargeType = ChargeType.Dynamic
const dynamicAmount = 3n
const nftService = new NFTServiceAttributes()
nftService.amount = 1n
nftService.minCreditsRequired = 1n
nftService.maxCreditsToCharge = 5n

const amountToCharge = NFTServiceAttributes.getCreditsToCharge(
nftService,
chargeType,
dynamicAmount,
)
assert.equal(amountToCharge, 3n)
})
})

describe('As user I can register a mintable asset and manage some permissions', () => {
it('Should be able to publish a mintable DID attached to the new NFT1155 contract', async () => {
royaltyAttributes = getRoyaltyAttributes(nevermined, RoyaltyKind.Standard, royalties)
Expand Down
5 changes: 5 additions & 0 deletions integration/nevermined/NVMAppAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Nevermined,
ResourceAuthentication,
SubscriptionCreditsNFTApi,
Web3Error,
ZeroAddress,
} from '../../src'
import { config } from '../config'
Expand Down Expand Up @@ -104,12 +105,16 @@ describe('NVM App API', () => {
it('I want to connect my account', async () => {
assert.isFalse(nvmApp.isWeb3Connected())

assert.throws(() => nvmApp.sdk.accounts.list(), Web3Error)

defaultSigner = config.accounts[0]
signerAddress = await defaultSigner.getAddress()
console.log(`Account address: ${signerAddress}`)
await nvmApp.connect(signerAddress)

assert.isTrue(nvmApp.isWeb3Connected())

assert.doesNotThrow(() => nvmApp.sdk.accounts.list(), Web3Error)
})

it('I can calculate and include network fees', async () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "2.2.1",
"version": "2.2.2",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions src/nevermined/NvmApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ export class NvmApp {
return this.searchSDK.search
}

public get sdk(): Nevermined {
if (!this.isWeb3Connected())
throw new Web3Error('Web3 not connected, try calling the connect method first')
return this.fullSDK
}

public get networkFees(): { receiver: string; fee: bigint } {
return { receiver: this.networkFeeReceiver, fee: this.networkFee }
}
Expand Down

0 comments on commit 952dc8e

Please sign in to comment.