Skip to content

Commit

Permalink
Merge pull request #85 from art-by-city/73-get-curation-tx
Browse files Browse the repository at this point in the history
73 get curation tx
  • Loading branch information
jim-toth authored Oct 22, 2023
2 parents 3fc732a + df6408d commit 7f3484e
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 162 deletions.
20 changes: 20 additions & 0 deletions src/curations/curations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ export default class ArtByCityCurations {
return new Curation(this.warp, curationId)
}

async getTransaction(curationId: string): Promise<ArdbTransaction | null> {
console.log('curationId', curationId)

// const tx = await this.ardb
// .search('transaction')
// .id(curationId)
// .sort('HEIGHT_DESC')
// .findOne() as ArdbTransaction

// return tx

const txs = await this.ardb
.search('transactions')
.ids([curationId])
.sort('HEIGHT_DESC')
.find() as ArdbTransaction[]

return txs[0] || null
}

async createdBy(creator: string, cursor?: string) {
let query = this.ardb
.search('transactions')
Expand Down
154 changes: 76 additions & 78 deletions test/e2e/curation.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
import('mocha') // NB: this style import makes both webpack and typescript happy
import { expect } from 'chai'
import Arweave from 'arweave'
import { JWKInterface, LoggerFactory, WarpFactory } from 'warp-contracts'
import { JWKInterface } from 'warp-contracts'

import TestweaveJWK from '../testweave-keyfile.json'
import ArtByCity, { ArtByCityConfig } from '../../src'
// import { CurationContractStates } from '../../src/curations'

LoggerFactory.INST.logLevel('error')
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */
const jwk: JWKInterface = TestweaveJWK as JWKInterface
const jwk: JWKInterface = TestweaveJWK

// const arweave = Arweave.init({
// protocol: 'http',
// host: 'localhost',
// port: 1984
// })
// const warp = WarpFactory.forLocal()
// const config: Partial<ArtByCityConfig> = {
// environment: 'development',
// contracts: {
Expand All @@ -34,91 +32,91 @@ const arweave = Arweave.init({
host: 'arweave.net',
port: 443
})
const warp = WarpFactory.forMainnet({
inMemory: true,
dbLocation: '.art-by-city'
})
const config: Partial<ArtByCityConfig> = { environment: 'production' }

let ownableCurationContractId: string = ''

describe('Curation Module', () => {
context('Authenticated', () => {
it('TESTS ARE DISABLED!')
// it('creates curation contracts with jwk', async function () {
// this.timeout(0)
// const address = await arweave.wallets.jwkToAddress(jwk)
// const abc = new ArtByCity(arweave, config)
// const title = 'My Ownable Curation'
// const description = 'My Ownable Curation Description'

// const id = await abc
// .connect(jwk)
// .curations
// .create('ownable', {
// owner: address,
// title,
// description
// })
// expect(id).to.be.a('string').with.length(43)

// // NB: set up for reading tests below
// ownableCurationContractId = id

// return
// })

// it('creates curation contracts with injected signer', async function () {
// this.timeout(0)
// if (!window || !window.arweaveWallet) { return }
// await window.arweaveWallet.connect(
// ['ACCESS_ADDRESS', 'SIGN_TRANSACTION', 'ACCESS_PUBLIC_KEY', 'SIGNATURE']
// )
// const address = await arweave.wallets.jwkToAddress(jwk)
// const abc = new ArtByCity(arweave, config)
// const title = 'My Ownable Curation'
// const description = 'My Ownable Curation Description'

// const id = await abc
// .connect()
// .curations
// .create('ownable', {
// owner: address,
// title,
// description
// })
// expect(id).to.be.a('string').with.length(43)

// // NB: set up for reading tests below
// ownableCurationContractId = id

// return
// })

it('creates whitelist curation contracts')
it('creates collaborative curation contracts')
it('creates collaborative whitelist curation contracts')
it.skip('creates curation contracts with jwk', async function () {
this.timeout(0)
const address = await arweave.wallets.jwkToAddress(jwk)
const abc = new ArtByCity(arweave, config)
const title = 'My Ownable Curation'
const description = 'My Ownable Curation Description'

const id = await abc
.connect(jwk)
.curations
.create('ownable', {
owner: address,
title,
description
})
expect(id).to.be.a('string').with.length(43)

// NB: set up for reading tests below
ownableCurationContractId = id

return
})

it.skip('creates curation contracts with injected signer', async function () {
this.timeout(0)
if (!window || !window.arweaveWallet) { return }
await window.arweaveWallet.connect(
['ACCESS_ADDRESS', 'SIGN_TRANSACTION', 'ACCESS_PUBLIC_KEY', 'SIGNATURE']
)
const address = await arweave.wallets.jwkToAddress(jwk)
const abc = new ArtByCity(arweave, config)
const title = 'My Ownable Curation'
const description = 'My Ownable Curation Description'

const id = await abc
.connect()
.curations
.create('ownable', {
owner: address,
title,
description
})
expect(id).to.be.a('string').with.length(43)

// NB: set up for reading tests below
ownableCurationContractId = id

return
})
})
context('Unauthenticated', () => {
// it('fetches curation contracts by id', async () => {
// const address = await arweave.wallets.jwkToAddress(jwk)
// const abc = new ArtByCity(arweave, config)
it.skip('fetches curation contracts by id', async () => {
const address = await arweave.wallets.jwkToAddress(jwk)
const abc = new ArtByCity(arweave, config)

// const curation = abc.curations.get(ownableCurationContractId)
// const { cachedValue: { state } } = await curation.contract.readState()
const curation = abc.curations.get(ownableCurationContractId)
const { cachedValue: { state } } = await curation.contract.readState()

// expect(state).to.be.an('object').with.property('owner')
// expect(state.owner).to.be.a('string').that.equals(address)
// })
expect(state).to.be.an('object').with.property('owner')
expect(state.owner).to.be.a('string').that.equals(address)
})

it.skip('queries curations by creator', async () => {
const address = await arweave.wallets.jwkToAddress(jwk)
const abc = new ArtByCity(arweave, config)

const { curations } = await abc.curations.createdBy(address)

expect(curations).to.be.an('array').that.is.not.empty
})

// it('queries curations by creator', async () => {
// const address = await arweave.wallets.jwkToAddress(jwk)
// const abc = new ArtByCity(arweave, config)
it('fetches curation transaction by id', async () => {
const abc = new ArtByCity(arweave, config)

// const { curations } = await abc.curations.createdBy(address)
const tx = await abc
.curations
.getTransaction('N_nbvz1vWrNI1kl0Nxefgi3Zo0p9F-onoF1mafWaKUU')

// expect(curations).to.be.an('array').that.is.not.empty
// })
expect(tx).to.not.be.null
})
})
})
/* eslint-enable */
Loading

0 comments on commit 7f3484e

Please sign in to comment.