|
| 1 | +package ledger |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/Peersyst/xrpl-go/xrpl/testutil" |
| 7 | + "github.com/Peersyst/xrpl-go/xrpl/transaction/types" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestPermissionedDomain_EntryType(t *testing.T) { |
| 12 | + permissionedDomain := &PermissionedDomain{} |
| 13 | + require.Equal(t, permissionedDomain.EntryType(), PermissionedDomainEntry) |
| 14 | +} |
| 15 | + |
| 16 | +func TestPermissionedDomain(t *testing.T) { |
| 17 | + |
| 18 | + tests := []struct { |
| 19 | + name string |
| 20 | + permissionedDomain *PermissionedDomain |
| 21 | + expected string |
| 22 | + }{ |
| 23 | + { |
| 24 | + name: "pass - valid PermissionedDomain", |
| 25 | + permissionedDomain: &PermissionedDomain{ |
| 26 | + Index: types.Hash256("3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F"), |
| 27 | + LedgerEntryType: PermissionedDomainEntry, |
| 28 | + Fee: types.XRPCurrencyAmount(10), |
| 29 | + Flags: 0, |
| 30 | + Owner: types.Address("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"), |
| 31 | + OwnerNode: "0000000000000000", |
| 32 | + Sequence: 390, |
| 33 | + AcceptedCredentials: types.AuthorizeCredentialList{ |
| 34 | + { |
| 35 | + Credential: types.Credential{ |
| 36 | + Issuer: types.Address("ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"), |
| 37 | + CredentialType: types.CredentialType("6D795F63726564656E7469616C"), |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + PreviousTxnID: types.Hash256("E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904"), |
| 42 | + PreviousTxnLgrSeq: 8734523, |
| 43 | + }, |
| 44 | + expected: `{ |
| 45 | + "index": "3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F", |
| 46 | + "LedgerEntryType": "PermissionedDomain", |
| 47 | + "Fee": "10", |
| 48 | + "Flags": 0, |
| 49 | + "Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", |
| 50 | + "OwnerNode": "0000000000000000", |
| 51 | + "Sequence": 390, |
| 52 | + "AcceptedCredentials": [ |
| 53 | + { |
| 54 | + "Credential": { |
| 55 | + "Issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", |
| 56 | + "CredentialType": "6D795F63726564656E7469616C" |
| 57 | + } |
| 58 | + } |
| 59 | + ], |
| 60 | + "PreviousTxnID": "E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904", |
| 61 | + "PreviousTxnLgrSeq": 8734523 |
| 62 | +}`, |
| 63 | + }, |
| 64 | + } |
| 65 | + for _, test := range tests { |
| 66 | + t.Run(test.name, func(t *testing.T) { |
| 67 | + if err := testutil.SerializeAndDeserialize(t, test.permissionedDomain, test.expected); err != nil { |
| 68 | + t.Error(err) |
| 69 | + } |
| 70 | + }) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +func TestPermissionedDomain_Flatten(t *testing.T) { |
| 75 | + tests := []struct { |
| 76 | + name string |
| 77 | + permissionedDomain *PermissionedDomain |
| 78 | + expected string |
| 79 | + }{ |
| 80 | + { |
| 81 | + name: "pass - valid PermissionedDomain", |
| 82 | + permissionedDomain: &PermissionedDomain{ |
| 83 | + Index: types.Hash256("3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F"), |
| 84 | + LedgerEntryType: PermissionedDomainEntry, |
| 85 | + Fee: types.XRPCurrencyAmount(10), |
| 86 | + Flags: 0, |
| 87 | + Owner: types.Address("rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn"), |
| 88 | + OwnerNode: "0000000000000000", |
| 89 | + Sequence: 390, |
| 90 | + AcceptedCredentials: types.AuthorizeCredentialList{ |
| 91 | + { |
| 92 | + Credential: types.Credential{ |
| 93 | + Issuer: types.Address("ra5nK24KXen9AHvsdFTKHSANinZseWnPcX"), |
| 94 | + CredentialType: types.CredentialType("6D795F63726564656E7469616C"), |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + PreviousTxnID: types.Hash256("E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904"), |
| 99 | + PreviousTxnLgrSeq: 8734523, |
| 100 | + }, |
| 101 | + expected: `{ |
| 102 | + "index": "3DFA1DDEA27AF7E466DE395CCB16158E07ECA6BC4EB5580F75EBD39DE833645F", |
| 103 | + "LedgerEntryType": "PermissionedDomain", |
| 104 | + "Fee": "10", |
| 105 | + "Flags": 0, |
| 106 | + "Owner": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", |
| 107 | + "OwnerNode": "0000000000000000", |
| 108 | + "Sequence": 390, |
| 109 | + "AcceptedCredentials": [ |
| 110 | + { |
| 111 | + "Credential": { |
| 112 | + "Issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", |
| 113 | + "CredentialType": "6D795F63726564656E7469616C" |
| 114 | + } |
| 115 | + } |
| 116 | + ], |
| 117 | + "PreviousTxnID": "E7E3F2BBAAF48CF893896E48DC4A02BDA0C747B198D5AE18BC3D7567EE64B904", |
| 118 | + "PreviousTxnLgrSeq": 8734523 |
| 119 | + }`, |
| 120 | + }, |
| 121 | + } |
| 122 | + for _, test := range tests { |
| 123 | + t.Run(test.name, func(t *testing.T) { |
| 124 | + if err := testutil.CompareFlattenAndExpected(test.permissionedDomain.Flatten(), []byte(test.expected)); err != nil { |
| 125 | + t.Error(err) |
| 126 | + } |
| 127 | + }) |
| 128 | + } |
| 129 | +} |
0 commit comments