Signer extends NeoSerializable { @Override public void serialize(BinaryWriter writer) throws IOException { writer.writeSerializableFixed(this.account); writer.writeByte(WitnessScope.combineScopes(this.scopes)); if (scopes.contains(WitnessScope.CUSTOM_CONTRACTS)) { writer.writeSerializableVariable(this.allowedContracts); } if (scopes.contains(WitnessScope.CUSTOM_GROUPS)) { writer.writeSerializableVariable(this.allowedGroups); } } Signer(); private  Signer(Builder builder); static Signer feeOnly(ScriptHash account); static Signer calledByEntry(ScriptHash account); static Signer global(ScriptHash account); ScriptHash getScriptHash(); List<WitnessScope> getScopes(); List<ScriptHash> getAllowedContracts(); List<ECKeyPair.ECPublicKey> getAllowedGroups(); @Override void deserialize(BinaryReader reader); @Override void serialize(BinaryWriter writer); @Override int getSize(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void serializeCustomGroupsScope() throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); BinaryWriter writer = new BinaryWriter(outStream); new Signer.Builder() .account(acctScriptHash) .allowedGroups(groupPubKey1, groupPubKey2) .build() .serialize(writer); byte[] actual = outStream.toByteArray(); byte[] expected = Numeric.hexStringToByteArray("" + Numeric.reverseHexString(acctScriptHash.toString()) + Numeric.toHexStringNoPrefix(WitnessScope.CUSTOM_GROUPS.byteValue()) + "02" + Numeric.toHexStringNoPrefix(groupPubKey1.toArray()) + Numeric.toHexStringNoPrefix(groupPubKey2.toArray())); assertArrayEquals(expected, actual); }
@Test public void serializeWithMultipleScopesContractsAndGroups() throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); BinaryWriter writer = new BinaryWriter(outStream); new Signer.Builder() .account(acctScriptHash) .allowedGroups(groupPubKey1, groupPubKey2) .allowedContracts(contract1, contract2) .scopes(WitnessScope.CALLED_BY_ENTRY) .build() .serialize(writer); byte[] actual = outStream.toByteArray(); byte[] expected = Numeric.hexStringToByteArray("" + Numeric.reverseHexString(acctScriptHash.toString()) + "31" + "02" + Numeric.reverseHexString(contract1.toString()) + Numeric.reverseHexString(contract2.toString()) + "02" + Numeric.toHexStringNoPrefix(groupPubKey1.toArray()) + Numeric.toHexStringNoPrefix(groupPubKey2.toArray())); assertArrayEquals(expected, actual); }