|
| 1 | +import {GrantEnums} from 'lib/desmos/msgtypes'; |
| 2 | +import { |
| 3 | + buildGrantAllowanceEncode, |
| 4 | + buildGrantMsgEncodes, |
| 5 | + buildRevokeAllowanceEncode, |
| 6 | + buildRevokeGrantMsgEncodes, |
| 7 | +} from './utils'; |
| 8 | + |
| 9 | +describe('hooks: useAddOrUpdateGrants utils', () => { |
| 10 | + const grantee = 'i-am-a-grantee'; |
| 11 | + const granter = 'i-am-a-granter'; |
| 12 | + const grants = [GrantEnums.MsgCreatePost, GrantEnums.MsgCreateRelationship]; |
| 13 | + |
| 14 | + beforeAll(() => { |
| 15 | + jest.useFakeTimers('modern').setSystemTime(new Date('2077-01-01')); |
| 16 | + }); |
| 17 | + |
| 18 | + afterAll(() => { |
| 19 | + jest.useRealTimers(); |
| 20 | + }); |
| 21 | + |
| 22 | + describe('buildRevokeAllowanceEncode', () => { |
| 23 | + it('properly builds a MsgRevokeAllowanceEncodeObject', () => { |
| 24 | + // msgEncodeObject |
| 25 | + const msgEO = buildRevokeAllowanceEncode({grantee, granter}); |
| 26 | + |
| 27 | + expect(msgEO).toEqual({ |
| 28 | + typeUrl: '/cosmos.feegrant.v1beta1.MsgRevokeAllowance', |
| 29 | + value: {granter: 'i-am-a-granter', grantee: 'i-am-a-grantee'}, |
| 30 | + }); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('buildGrantAllowanceEncode', () => { |
| 35 | + it('properly builds a MsgGrantAllowanceEncodeObject', () => { |
| 36 | + const msgEO = buildGrantAllowanceEncode({grantee, granter, grants}); |
| 37 | + |
| 38 | + expect(JSON.stringify(msgEO)).toEqual( |
| 39 | + JSON.stringify({ |
| 40 | + typeUrl: '/cosmos.feegrant.v1beta1.MsgGrantAllowance', |
| 41 | + value: { |
| 42 | + granter: 'i-am-a-granter', |
| 43 | + grantee: 'i-am-a-grantee', |
| 44 | + allowance: { |
| 45 | + typeUrl: '/cosmos.feegrant.v1beta1.AllowedMsgAllowance', |
| 46 | + value: { |
| 47 | + type: 'Buffer', |
| 48 | + data: [ |
| 49 | + 10, 41, 10, 39, 47, 99, 111, 115, 109, 111, 115, 46, 102, 101, |
| 50 | + 101, 103, 114, 97, 110, 116, 46, 118, 49, 98, 101, 116, 97, |
| 51 | + 49, 46, 66, 97, 115, 105, 99, 65, 108, 108, 111, 119, 97, 110, |
| 52 | + 99, 101, 18, 30, 47, 100, 101, 115, 109, 111, 115, 46, 112, |
| 53 | + 111, 115, 116, 115, 46, 118, 50, 46, 77, 115, 103, 67, 114, |
| 54 | + 101, 97, 116, 101, 80, 111, 115, 116, 18, 46, 47, 100, 101, |
| 55 | + 115, 109, 111, 115, 46, 114, 101, 108, 97, 116, 105, 111, 110, |
| 56 | + 115, 104, 105, 112, 115, 46, 118, 49, 46, 77, 115, 103, 67, |
| 57 | + 114, 101, 97, 116, 101, 82, 101, 108, 97, 116, 105, 111, 110, |
| 58 | + 115, 104, 105, 112, |
| 59 | + ], |
| 60 | + }, |
| 61 | + }, |
| 62 | + }, |
| 63 | + }), |
| 64 | + ); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + describe('buildGrantMsgEncodes', () => { |
| 69 | + it('properly builds an array of MsgGRantEncodeObjects', () => { |
| 70 | + const msgEO = buildGrantMsgEncodes({grantee, granter, grants}); |
| 71 | + |
| 72 | + expect(JSON.stringify(msgEO)).toEqual( |
| 73 | + JSON.stringify([ |
| 74 | + { |
| 75 | + typeUrl: '/cosmos.authz.v1beta1.MsgGrant', |
| 76 | + value: { |
| 77 | + granter: 'i-am-a-granter', |
| 78 | + grantee: 'i-am-a-grantee', |
| 79 | + grant: { |
| 80 | + authorization: { |
| 81 | + typeUrl: |
| 82 | + '/desmos.subspaces.v3.authz.GenericSubspaceAuthorization', |
| 83 | + value: { |
| 84 | + type: 'Buffer', |
| 85 | + data: [ |
| 86 | + 10, 1, 5, 18, 30, 47, 100, 101, 115, 109, 111, 115, 46, |
| 87 | + 112, 111, 115, 116, 115, 46, 118, 50, 46, 77, 115, 103, |
| 88 | + 67, 114, 101, 97, 116, 101, 80, 111, 115, 116, |
| 89 | + ], |
| 90 | + }, |
| 91 | + }, |
| 92 | + expiration: { |
| 93 | + seconds: {low: -602922496, high: 0, unsigned: false}, |
| 94 | + nanos: 0, |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + { |
| 100 | + typeUrl: '/cosmos.authz.v1beta1.MsgGrant', |
| 101 | + value: { |
| 102 | + granter: 'i-am-a-granter', |
| 103 | + grantee: 'i-am-a-grantee', |
| 104 | + grant: { |
| 105 | + authorization: { |
| 106 | + typeUrl: |
| 107 | + '/desmos.subspaces.v3.authz.GenericSubspaceAuthorization', |
| 108 | + value: { |
| 109 | + type: 'Buffer', |
| 110 | + data: [ |
| 111 | + 10, 1, 5, 18, 46, 47, 100, 101, 115, 109, 111, 115, 46, |
| 112 | + 114, 101, 108, 97, 116, 105, 111, 110, 115, 104, 105, 112, |
| 113 | + 115, 46, 118, 49, 46, 77, 115, 103, 67, 114, 101, 97, 116, |
| 114 | + 101, 82, 101, 108, 97, 116, 105, 111, 110, 115, 104, 105, |
| 115 | + 112, |
| 116 | + ], |
| 117 | + }, |
| 118 | + }, |
| 119 | + expiration: { |
| 120 | + seconds: {low: -602922496, high: 0, unsigned: false}, |
| 121 | + nanos: 0, |
| 122 | + }, |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + ]), |
| 127 | + ); |
| 128 | + }); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('buildRevokeGrantMsgEncodes', () => { |
| 132 | + it('properly builds an array og MsgRevokeEncodeObjects', () => { |
| 133 | + const msgEO = buildRevokeGrantMsgEncodes({grants, grantee, granter}); |
| 134 | + |
| 135 | + expect(msgEO).toEqual([ |
| 136 | + { |
| 137 | + typeUrl: '/cosmos.authz.v1beta1.MsgRevoke', |
| 138 | + value: { |
| 139 | + granter: 'i-am-a-granter', |
| 140 | + grantee: 'i-am-a-grantee', |
| 141 | + msgTypeUrl: '/desmos.posts.v2.MsgCreatePost', |
| 142 | + }, |
| 143 | + }, |
| 144 | + { |
| 145 | + typeUrl: '/cosmos.authz.v1beta1.MsgRevoke', |
| 146 | + value: { |
| 147 | + granter: 'i-am-a-granter', |
| 148 | + grantee: 'i-am-a-grantee', |
| 149 | + msgTypeUrl: '/desmos.relationships.v1.MsgCreateRelationship', |
| 150 | + }, |
| 151 | + }, |
| 152 | + ]); |
| 153 | + }); |
| 154 | + }); |
| 155 | +}); |
0 commit comments