Parse transaction flags into map of names:booleans (#2734)

* overview logic of parsetransactionflags

* parse transaction flags works

* basic tests

* eslint and docs

* linting

* lint

* fix typing

* test fix

* revert import delete

* lint

* integration fix

* lint

* imports

* added numeric test

* add history log

* history update
This commit is contained in:
achowdhry-ripple
2024-08-07 11:44:57 -04:00
committed by GitHub
parent a46e86f17e
commit f3960c3ccc
4 changed files with 89 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ import { isFlagEnabled } from '../../src/models/utils'
import {
setTransactionFlagsToNumber,
parseAccountRootFlags,
parseTransactionFlags,
} from '../../src/models/utils/flags'
/**
@@ -207,5 +208,60 @@ describe('Models Utils', function () {
assert.isUndefined(parsed.lsfDisallowIncomingTrustline)
assert.isUndefined(parsed.lsfAllowTrustLineClawback)
})
it('parseTransactionFlags all enabled', function () {
const tx: PaymentChannelClaim = {
Account: 'r...',
TransactionType: 'PaymentChannelClaim',
Channel:
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
Flags: {
tfRenew: true,
tfClose: false,
},
}
const expected = {
tfRenew: true,
}
const flagsMap = parseTransactionFlags(tx)
assert.notStrictEqual(flagsMap, expected)
})
it('parseTransactionFlags all false', function () {
const tx: PaymentChannelClaim = {
Account: 'r...',
TransactionType: 'PaymentChannelClaim',
Channel:
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
Flags: {
tfRenew: false,
tfClose: false,
},
}
const expected = {}
const flagsMap = parseTransactionFlags(tx)
assert.notStrictEqual(flagsMap, expected)
})
it('parseTransactionFlags flag is already numeric', function () {
const tx: PaymentChannelClaim = {
Account: 'r...',
TransactionType: 'PaymentChannelClaim',
Channel:
'C1AE6DDDEEC05CF2978C0BAD6FE302948E9533691DC749DCDD3B9E5992CA6198',
Flags: 65536,
}
const expected = {
tfRenew: true,
}
const flagsMap = parseTransactionFlags(tx)
assert.notStrictEqual(flagsMap, expected)
})
})
})