-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added unit test for drain_delegate in contract api
re #2068
- Loading branch information
1 parent
446aceb
commit e3479df
Showing
2 changed files
with
167 additions
and
0 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
137 changes: 137 additions & 0 deletions
137
packages/taquito/test/operations/drain-delegate.spec.ts
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,137 @@ | ||
import { DrainDelegateOperation } from '../../src/operations'; | ||
import { | ||
OperationContentsAndResult, | ||
OpKind, | ||
OperationContentsAndResultDrainDelegate, | ||
} from '@taquito/rpc'; | ||
import { ForgedBytes } from '../../src/operations/types'; | ||
import { defaultConfigConfirmation } from '../../src/context'; | ||
|
||
describe('DrainDelegate operation', () => { | ||
let fakeContext: any; | ||
|
||
const fakeForgedBytes = {} as ForgedBytes; | ||
|
||
const successfulResult = [ | ||
{ | ||
kind: 'drain_delegate', | ||
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
metadata: { | ||
balance_updates: [ | ||
{ | ||
kind: 'contract', | ||
contract: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
change: '-15525772494', | ||
origin: 'block', | ||
}, | ||
{ | ||
kind: 'contract', | ||
contract: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
change: '15525772494', | ||
origin: 'block', | ||
}, | ||
{ | ||
kind: 'contract', | ||
contract: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
change: '-156825984', | ||
origin: 'block', | ||
}, | ||
{ | ||
kind: 'contract', | ||
contract: 'tz1hoyMUiJYYr4FRPMU8Z7WJzYkqgjygjaTy', | ||
change: '156825984', | ||
origin: 'block', | ||
}, | ||
], | ||
}, | ||
}, | ||
] as OperationContentsAndResult[]; | ||
|
||
beforeEach(() => { | ||
fakeContext = { | ||
rpc: { | ||
getBlock: jest.fn(), | ||
}, | ||
config: { ...defaultConfigConfirmation }, | ||
}; | ||
|
||
fakeContext.rpc.getBlock.mockResolvedValue({ | ||
operations: [[{ hash: 'oo7gLAnWgTe7XtoYjgnkNBXDDvUy2e1DVcVwtvALxajx6KRzkXb' }], [], [], []], | ||
header: { | ||
level: 1, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should return OperationMetadataBalanceUpdates of DrainDelegate operation', () => { | ||
const op = new DrainDelegateOperation( | ||
'oo7gLAnWgTe7XtoYjgnkNBXDDvUy2e1DVcVwtvALxajx6KRzkXb', | ||
{ | ||
kind: OpKind.DRAIN_DELEGATE, | ||
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
}, | ||
fakeForgedBytes, | ||
successfulResult, | ||
fakeContext | ||
); | ||
|
||
expect(op.operationResults).toEqual( | ||
(successfulResult[0] as OperationContentsAndResultDrainDelegate).metadata.balance_updates | ||
); | ||
}); | ||
|
||
it('should return consensusKey of DrainDelegate operation', () => { | ||
const op = new DrainDelegateOperation( | ||
'oo7gLAnWgTe7XtoYjgnkNBXDDvUy2e1DVcVwtvALxajx6KRzkXb', | ||
{ | ||
kind: OpKind.DRAIN_DELEGATE, | ||
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
}, | ||
fakeForgedBytes, | ||
successfulResult, | ||
fakeContext | ||
); | ||
|
||
expect(op.consensusKey).toEqual('tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj'); | ||
}); | ||
|
||
it('should return delegate of DrainDelegate operation', () => { | ||
const op = new DrainDelegateOperation( | ||
'oo7gLAnWgTe7XtoYjgnkNBXDDvUy2e1DVcVwtvALxajx6KRzkXb', | ||
{ | ||
kind: OpKind.DRAIN_DELEGATE, | ||
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
}, | ||
fakeForgedBytes, | ||
successfulResult, | ||
fakeContext | ||
); | ||
|
||
expect(op.delegate).toEqual('tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv'); | ||
}); | ||
|
||
it('should return destination of DrainDelegate operation', () => { | ||
const op = new DrainDelegateOperation( | ||
'oo7gLAnWgTe7XtoYjgnkNBXDDvUy2e1DVcVwtvALxajx6KRzkXb', | ||
{ | ||
kind: OpKind.DRAIN_DELEGATE, | ||
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv', | ||
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj', | ||
}, | ||
fakeForgedBytes, | ||
successfulResult, | ||
fakeContext | ||
); | ||
|
||
expect(op.destination).toEqual('tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj'); | ||
}); | ||
}); |