Skip to content

Commit

Permalink
Revert "[TS SDK] Adding condition to determine mutable types in SDK (… (
Browse files Browse the repository at this point in the history
MystenLabs#8732)

This reverts commit 1fe9765.
  • Loading branch information
ebmifa authored Mar 1, 2023
1 parent 1fe9765 commit 95651f3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 154 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions crates/sui-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ pub fn resolve_move_function_args(
type_args: &[TypeTag],
combined_args_json: Vec<SuiJsonValue>,
allow_arbitrary_function_call: bool,
) -> Result<Vec<(SuiJsonCallArg, SignatureToken)>, anyhow::Error> {
) -> Result<Vec<SuiJsonCallArg>, anyhow::Error> {
// Extract the expected function signature
let module = package.deserialize_module(&module_ident)?;
let function_str = function.as_ident_str();
Expand Down Expand Up @@ -671,13 +671,7 @@ pub fn resolve_move_function_args(
}

// Check that the args are valid and convert to the correct format
let call_args = resolve_call_args(&view, type_args, &combined_args_json, parameters)?;
let tupled_call_args = call_args
.iter()
.zip(parameters.iter())
.map(|(arg, expected_type)| (arg.clone(), expected_type.clone()))
.collect::<Vec<(SuiJsonCallArg, SignatureToken)>>();
Ok(tupled_call_args)
resolve_call_args(&view, type_args, &combined_args_json, parameters)
}

fn convert_string_to_u256(s: &str) -> Result<U256, anyhow::Error> {
Expand Down
22 changes: 11 additions & 11 deletions crates/sui-json/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,23 +476,23 @@ fn test_basic_args_linter_top_level() {
assert!(!json_args.is_empty());

assert_eq!(
json_args[1].0,
json_args[1],
SuiJsonCallArg::Pure(bcs::to_bytes(&monster_name_raw.as_bytes().to_vec()).unwrap())
);
assert_eq!(
json_args[2].0,
json_args[2],
SuiJsonCallArg::Pure(bcs::to_bytes(&(monster_img_id_raw.parse::<u64>().unwrap())).unwrap()),
);
assert_eq!(
json_args[3].0,
json_args[3],
SuiJsonCallArg::Pure(bcs::to_bytes(&(breed_raw as u8)).unwrap())
);
assert_eq!(
json_args[4].0,
json_args[4],
SuiJsonCallArg::Pure(bcs::to_bytes(&(monster_affinity_raw as u8)).unwrap()),
);
assert_eq!(
json_args[5].0,
json_args[5],
SuiJsonCallArg::Pure(bcs::to_bytes(&monster_description_raw.as_bytes().to_vec()).unwrap()),
);

Expand Down Expand Up @@ -560,14 +560,14 @@ fn test_basic_args_linter_top_level() {
.unwrap();

assert_eq!(
args[0].0,
args[0],
SuiJsonCallArg::Pure(bcs::to_bytes(&(value_raw.parse::<u64>().unwrap())).unwrap())
);

// Need to verify this specially
// BCS serialzes addresses like vectors so there's a length prefix, which makes the vec longer by 1
assert_eq!(
args[1].0,
args[1],
SuiJsonCallArg::Pure(bcs::to_bytes(&AccountAddress::from(address)).unwrap()),
);

Expand Down Expand Up @@ -604,7 +604,7 @@ fn test_basic_args_linter_top_level() {
.unwrap();

assert_eq!(
args[0].0,
args[0],
SuiJsonCallArg::Object(
ObjectID::from_hex_literal(&format!("0x{:02x}", object_id_raw)).unwrap()
)
Expand All @@ -613,7 +613,7 @@ fn test_basic_args_linter_top_level() {
// Need to verify this specially
// BCS serialzes addresses like vectors so there's a length prefix, which makes the vec longer by 1
assert_eq!(
args[1].0,
args[1],
SuiJsonCallArg::Pure(bcs::to_bytes(&AccountAddress::from(address)).unwrap())
);

Expand Down Expand Up @@ -652,9 +652,9 @@ fn test_basic_args_linter_top_level() {
)
.unwrap();

assert!(matches!(args[0].0, SuiJsonCallArg::ObjVec { .. }));
assert!(matches!(args[0], SuiJsonCallArg::ObjVec { .. }));

if let SuiJsonCallArg::ObjVec(vec) = &args[0].0 {
if let SuiJsonCallArg::ObjVec(vec) = &args[0] {
assert_eq!(vec.len(), 2);
assert_eq!(
vec[0],
Expand Down
1 change: 0 additions & 1 deletion crates/sui-transaction-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ async-trait = "0.1.61"
futures = "0.3.23"
bcs = "0.1.4"

move-binary-format.workspace = true
sui-json-rpc-types= { path = "../sui-json-rpc-types" }
sui-types = { path = "../sui-types" }
sui-json = { path = "../sui-json" }
Expand Down
20 changes: 5 additions & 15 deletions crates/sui-transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ use sui_types::messages::{
TransactionKind, TransferObject,
};

use move_binary_format::file_format::SignatureToken;

use sui_types::governance::{
ADD_DELEGATION_LOCKED_COIN_FUN_NAME, ADD_DELEGATION_MUL_COIN_FUN_NAME,
WITHDRAW_DELEGATION_FUN_NAME,
Expand Down Expand Up @@ -327,7 +325,6 @@ impl<Mode: ExecutionMode> TransactionBuilder<Mode> {
&self,
id: ObjectID,
objects: &mut BTreeMap<ObjectID, Object>,
expected_type: SignatureToken,
) -> Result<ObjectArg, anyhow::Error> {
let response = self.0.get_object(id).await?;
let obj: Object = response.into_object()?.try_into()?;
Expand All @@ -341,11 +338,7 @@ impl<Mode: ExecutionMode> TransactionBuilder<Mode> {
id,
initial_shared_version,
// todo(RWLocks) - do we want to parametrise this?
mutable: match expected_type {
// Only set mutable reference types to true
SignatureToken::MutableReference(_) => true,
_ => false,
},
mutable: true, // using mutable reference by default here.
},
Owner::AddressOwner(_) | Owner::ObjectOwner(_) | Owner::Immutable => {
ObjectArg::ImmOrOwnedObject(obj_ref)
Expand Down Expand Up @@ -374,7 +367,7 @@ impl<Mode: ExecutionMode> TransactionBuilder<Mode> {
ProtocolConfig::get_for_min_version().max_move_package_size(),
)?;

let json_args_and_tokens = resolve_move_function_args(
let json_args = resolve_move_function_args(
&package,
module.clone(),
function.clone(),
Expand All @@ -384,19 +377,16 @@ impl<Mode: ExecutionMode> TransactionBuilder<Mode> {
)?;
let mut args = Vec::new();
let mut objects = BTreeMap::new();
for (arg, expected_type) in json_args_and_tokens {
for arg in json_args {
args.push(match arg {
SuiJsonCallArg::Object(id) => {
CallArg::Object(self.get_object_arg(id, &mut objects, expected_type).await?)
CallArg::Object(self.get_object_arg(id, &mut objects).await?)
}
SuiJsonCallArg::Pure(p) => CallArg::Pure(p),
SuiJsonCallArg::ObjVec(v) => {
let mut object_ids = vec![];
for id in v {
object_ids.push(
self.get_object_arg(id, &mut objects, expected_type.clone())
.await?,
);
object_ids.push(self.get_object_arg(id, &mut objects).await?);
}
CallArg::ObjVec(object_ids)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,12 @@ export class CallArgSerializer {
return hasTxContext ? params.slice(0, params.length - 1) : params;
}

async newObjectArg(
objectId: string,
expectedType: SuiMoveNormalizedType,
): Promise<ObjectArg> {
async newObjectArg(objectId: string): Promise<ObjectArg> {
const object = await this.provider.getObject(objectId);
const initialSharedVersion = getSharedObjectInitialVersion(object);

const mutable = true; // Defaulted to True to match current behavior.
if (initialSharedVersion) {
const mutable =
typeof expectedType === 'object' && 'MutableReference' in expectedType;

return { Shared: { objectId, initialSharedVersion, mutable } };
}
return { ImmOrOwned: getObjectReference(object)! };
Expand Down Expand Up @@ -199,7 +194,7 @@ export class CallArgSerializer {
)}`,
);
}
return { Object: await this.newObjectArg(argVal, expectedType) };
return { Object: await this.newObjectArg(argVal) };
}

if (
Expand All @@ -215,7 +210,7 @@ export class CallArgSerializer {
}
return {
ObjVec: await Promise.all(
argVal.map((arg) => this.newObjectArg(arg as string, expectedType)),
argVal.map((arg) => this.newObjectArg(arg as string)),
),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module serializer::serializer_tests {
use sui::tx_context::{Self, TxContext};
use sui::transfer;
use sui::clock::{Self, Clock};

public entry fun list<T: key + store, C>(
item: T,
Expand All @@ -19,10 +18,6 @@ module serializer::serializer_tests {
item
}

public entry fun timestamp_ms(clock: &Clock) {
clock::timestamp_ms(clock);
}

public fun test_abort() {
abort 0
}
Expand Down
105 changes: 1 addition & 104 deletions sdk/typescript/test/e2e/txn-serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ describe('Transaction Serialization and deserialization', () => {
let localSerializer: LocalTxnDataSerializer;
let rpcSerializer: RpcTxnDataSerializer;
let packageId: string;
let signer: RawSigner;

beforeAll(async () => {
toolbox = await setup();
localSerializer = new LocalTxnDataSerializer(toolbox.provider);
rpcSerializer = new RpcTxnDataSerializer(
toolbox.provider.connection.fullnode,
);
signer = new RawSigner(toolbox.keypair, toolbox.provider);
const signer = new RawSigner(toolbox.keypair, toolbox.provider);
const packagePath = __dirname + '/./data/serializer';
packageId = await publishPackage(signer, false, packagePath);
});
Expand Down Expand Up @@ -297,106 +296,4 @@ describe('Transaction Serialization and deserialization', () => {
} as UnserializedSignableTransaction;
expect(expectedTx).toEqual(deserialized);
});

it('Check mutable reference is true', async () => {
const coins = await toolbox.provider.getGasObjectsOwnedByAddress(
toolbox.address(),
);
const validators = await toolbox.getActiveValidators();
const validator_metadata = (validators[0] as SuiMoveObject).fields.metadata;
const validator_address = (validator_metadata as SuiMoveObject).fields
.sui_address;
const moveCall = {
packageObjectId: '0x2',
module: 'sui_system',
function: 'request_add_delegation_mul_coin',
typeArguments: [],
arguments: [
SUI_SYSTEM_STATE_OBJECT_ID,
[coins[2].objectId],
[String(100)],
validator_address,
],
gasBudget: DEFAULT_GAS_BUDGET,
gasPayment: coins[1].objectId,
} as MoveCallTransaction;

const localTxnBytes = await localSerializer.serializeToBytes(
toolbox.address(),
{ kind: 'moveCall', data: moveCall },
);

const deserializedTxnData: any =
deserializeTransactionBytesToTransactionData(
bcsForVersion(await toolbox.provider.getRpcApiVersion()),
localTxnBytes,
);

expect(
deserializedTxnData.kind.Single?.Call.arguments[0].Object.Shared.mutable,
).toBeTruthy();

const rpcTxnByes = await rpcSerializer.serializeToBytes(toolbox.address(), {
kind: 'moveCall',
data: moveCall,
});

const deserializedRpcTxnData: any =
deserializeTransactionBytesToTransactionData(
bcsForVersion(await toolbox.provider.getRpcApiVersion()),
rpcTxnByes,
);

expect(
deserializedRpcTxnData.kind.Single?.Call.arguments[0].Object.Shared
.mutable,
).toBeTruthy();
});

it('Check mutable reference false', async () => {
const coins = await toolbox.provider.getGasObjectsOwnedByAddress(
toolbox.address(),
);

const moveCall = {
packageObjectId: packageId,
module: 'serializer_tests',
function: 'timestamp_ms',
typeArguments: [],
arguments: ['0x0000000000000000000000000000000000000006'],
gasBudget: DEFAULT_GAS_BUDGET,
gasPayment: coins[1].objectId,
} as MoveCallTransaction;

const localTxnBytes = await localSerializer.serializeToBytes(
toolbox.address(),
{ kind: 'moveCall', data: moveCall },
);

const deserializedTxnData: any =
deserializeTransactionBytesToTransactionData(
bcsForVersion(await toolbox.provider.getRpcApiVersion()),
localTxnBytes,
);

expect(
deserializedTxnData.kind.Single?.Call.arguments[0].Object.Shared.mutable,
).toBeFalsy();

const rpcTxnByes = await rpcSerializer.serializeToBytes(toolbox.address(), {
kind: 'moveCall',
data: moveCall,
});

const deserializedRpcTxnData: any =
deserializeTransactionBytesToTransactionData(
bcsForVersion(await toolbox.provider.getRpcApiVersion()),
rpcTxnByes,
);

expect(
deserializedRpcTxnData.kind.Single?.Call.arguments[0].Object.Shared
.mutable,
).toBeFalsy();
});
});

0 comments on commit 95651f3

Please sign in to comment.