-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from ardriveapp/PE-726_excise_arfs_tag_from_da…
…ta_tx PE-726: Excise ArFS tag from data transactions
- Loading branch information
Showing
3 changed files
with
140 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import Arweave from 'arweave'; | ||
import { stubEntityID } from '../../tests/stubs'; | ||
import { ByteCount, FeeMultiple, stubTransactionID, UnixTime, W } from '../types'; | ||
import { readJWKFile } from '../utils/common'; | ||
import { ArFSDAO } from './arfsdao'; | ||
import { ArFSPublicFileMetaDataPrototype } from './arfs_prototypes'; | ||
import { ArFSPublicFileMetadataTransactionData } from './arfs_trx_data_types'; | ||
import { expect } from 'chai'; | ||
import { Tag } from 'arweave/node/lib/transaction'; | ||
|
||
describe('The ArFSDAO class', () => { | ||
const wallet = readJWKFile('./test_wallet.json'); | ||
const fakeArweave = Arweave.init({ | ||
host: 'localhost', | ||
port: 443, | ||
protocol: 'https', | ||
timeout: 600000 | ||
}); | ||
|
||
const arfsDao = new ArFSDAO(wallet, fakeArweave, true, 'ArFSDAO-Test', '1.0'); | ||
|
||
const stubFileMetaDataTrx = new ArFSPublicFileMetaDataPrototype( | ||
new ArFSPublicFileMetadataTransactionData( | ||
'Test Metadata', | ||
new ByteCount(10), | ||
new UnixTime(123456789), | ||
stubTransactionID, | ||
'text/plain' | ||
), | ||
stubEntityID, | ||
stubEntityID, | ||
stubEntityID | ||
); | ||
|
||
describe('prepareObjectTransaction function', () => { | ||
// Helper function to grab the decoded gql tags off of a Transaction | ||
const getDecodedTagName = (tag: Tag) => tag.get('name', { decode: true, string: true }); | ||
|
||
it('includes the base ArFS tags by default', async () => { | ||
const transaction = await arfsDao.prepareArFSObjectTransaction({ | ||
objectMetaData: stubFileMetaDataTrx, | ||
rewardSettings: { reward: W(10) } | ||
}); | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'ArFS')).to.exist; | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'App-Name')).to.exist; | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'App-Version')).to.exist; | ||
expect(transaction.tags.length).to.equal(9); | ||
}); | ||
|
||
it('includes the boost tag when boosted', async () => { | ||
const transaction = await arfsDao.prepareArFSObjectTransaction({ | ||
objectMetaData: stubFileMetaDataTrx, | ||
rewardSettings: { reward: W(10), feeMultiple: new FeeMultiple(1.5) } | ||
}); | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'Boost')).to.exist; | ||
expect(transaction.tags.length).to.equal(10); | ||
}); | ||
|
||
it('excludes the boost tag when boosted and boost tag is excluded', async () => { | ||
const transaction = await arfsDao.prepareArFSObjectTransaction({ | ||
objectMetaData: stubFileMetaDataTrx, | ||
rewardSettings: { reward: W(10), feeMultiple: new FeeMultiple(1.5) }, | ||
excludedTagNames: ['Boost'] | ||
}); | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'Boost')).to.be.undefined; | ||
expect(transaction.tags.length).to.equal(9); | ||
}); | ||
|
||
it('excludes ArFS tag if its within the exclusion array', async () => { | ||
const transaction = await arfsDao.prepareArFSObjectTransaction({ | ||
objectMetaData: stubFileMetaDataTrx, | ||
rewardSettings: { reward: W(10) }, | ||
excludedTagNames: ['ArFS'] | ||
}); | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'ArFS')).to.be.undefined; | ||
expect(transaction.tags.length).to.equal(8); | ||
}); | ||
|
||
it('can exclude multiple tags if provided within the exclusion array', async () => { | ||
const transaction = await arfsDao.prepareArFSObjectTransaction({ | ||
objectMetaData: stubFileMetaDataTrx, | ||
rewardSettings: { reward: W(10) }, | ||
excludedTagNames: ['ArFS', 'App-Version', 'App-Name'] | ||
}); | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'ArFS')).to.be.undefined; | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'App-Name')).to.be.undefined; | ||
expect(transaction.tags.find((tag) => getDecodedTagName(tag) === 'App-Version')).to.be.undefined; | ||
expect(transaction.tags.length).to.equal(6); | ||
}); | ||
}); | ||
}); |
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